@promptbook/website-crawler 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 +232 -190
- 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 +2 -2
- package/umd/index.umd.js +232 -190
- 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
|
@@ -24,7 +24,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
24
24
|
*
|
|
25
25
|
* @see https://github.com/webgptorg/promptbook
|
|
26
26
|
*/
|
|
27
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.
|
|
27
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.78.1';
|
|
28
28
|
/**
|
|
29
29
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
30
30
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -204,164 +204,25 @@ function just(value) {
|
|
|
204
204
|
}
|
|
205
205
|
|
|
206
206
|
/**
|
|
207
|
-
*
|
|
207
|
+
* Name for the Promptbook
|
|
208
|
+
*
|
|
209
|
+
* TODO: [🗽] Unite branding and make single place for it
|
|
208
210
|
*
|
|
209
211
|
* @public exported from `@promptbook/core`
|
|
210
212
|
*/
|
|
211
|
-
var
|
|
212
|
-
__extends(UnexpectedError, _super);
|
|
213
|
-
function UnexpectedError(message) {
|
|
214
|
-
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;
|
|
215
|
-
_this.name = 'UnexpectedError';
|
|
216
|
-
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
217
|
-
return _this;
|
|
218
|
-
}
|
|
219
|
-
return UnexpectedError;
|
|
220
|
-
}(Error));
|
|
221
|
-
|
|
213
|
+
var NAME = "Promptbook";
|
|
222
214
|
/**
|
|
223
|
-
*
|
|
224
|
-
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
225
|
-
*
|
|
226
|
-
* - Almost all primitives are serializable BUT:
|
|
227
|
-
* - `undefined` is not serializable
|
|
228
|
-
* - `NaN` is not serializable
|
|
229
|
-
* - Objects and arrays are serializable if all their properties are serializable
|
|
230
|
-
* - Functions are not serializable
|
|
231
|
-
* - Circular references are not serializable
|
|
232
|
-
* - `Date` objects are not serializable
|
|
233
|
-
* - `Map` and `Set` objects are not serializable
|
|
234
|
-
* - `RegExp` objects are not serializable
|
|
235
|
-
* - `Error` objects are not serializable
|
|
236
|
-
* - `Symbol` objects are not serializable
|
|
237
|
-
* - And much more...
|
|
215
|
+
* Email of the responsible person
|
|
238
216
|
*
|
|
239
|
-
* @
|
|
240
|
-
* @public exported from `@promptbook/utils`
|
|
241
|
-
*/
|
|
242
|
-
function checkSerializableAsJson(name, value) {
|
|
243
|
-
var e_1, _a;
|
|
244
|
-
if (value === undefined) {
|
|
245
|
-
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
246
|
-
}
|
|
247
|
-
else if (value === null) {
|
|
248
|
-
return;
|
|
249
|
-
}
|
|
250
|
-
else if (typeof value === 'boolean') {
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
else if (typeof value === 'number' && !isNaN(value)) {
|
|
254
|
-
return;
|
|
255
|
-
}
|
|
256
|
-
else if (typeof value === 'string') {
|
|
257
|
-
return;
|
|
258
|
-
}
|
|
259
|
-
else if (typeof value === 'symbol') {
|
|
260
|
-
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
261
|
-
}
|
|
262
|
-
else if (typeof value === 'function') {
|
|
263
|
-
throw new UnexpectedError("".concat(name, " is function"));
|
|
264
|
-
}
|
|
265
|
-
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
266
|
-
for (var i = 0; i < value.length; i++) {
|
|
267
|
-
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
else if (typeof value === 'object') {
|
|
271
|
-
if (value instanceof Date) {
|
|
272
|
-
throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
273
|
-
}
|
|
274
|
-
else if (value instanceof Map) {
|
|
275
|
-
throw new UnexpectedError("".concat(name, " is Map"));
|
|
276
|
-
}
|
|
277
|
-
else if (value instanceof Set) {
|
|
278
|
-
throw new UnexpectedError("".concat(name, " is Set"));
|
|
279
|
-
}
|
|
280
|
-
else if (value instanceof RegExp) {
|
|
281
|
-
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
282
|
-
}
|
|
283
|
-
else if (value instanceof Error) {
|
|
284
|
-
throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
285
|
-
}
|
|
286
|
-
else {
|
|
287
|
-
try {
|
|
288
|
-
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
289
|
-
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
290
|
-
if (subValue === undefined) {
|
|
291
|
-
// Note: undefined in object is serializable - it is just omited
|
|
292
|
-
continue;
|
|
293
|
-
}
|
|
294
|
-
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
298
|
-
finally {
|
|
299
|
-
try {
|
|
300
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
301
|
-
}
|
|
302
|
-
finally { if (e_1) throw e_1.error; }
|
|
303
|
-
}
|
|
304
|
-
try {
|
|
305
|
-
JSON.stringify(value); // <- TODO: [0]
|
|
306
|
-
}
|
|
307
|
-
catch (error) {
|
|
308
|
-
if (!(error instanceof Error)) {
|
|
309
|
-
throw error;
|
|
310
|
-
}
|
|
311
|
-
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
312
|
-
}
|
|
313
|
-
/*
|
|
314
|
-
TODO: [0] Is there some more elegant way to check circular references?
|
|
315
|
-
const seen = new Set();
|
|
316
|
-
const stack = [{ value }];
|
|
317
|
-
while (stack.length > 0) {
|
|
318
|
-
const { value } = stack.pop()!;
|
|
319
|
-
if (typeof value === 'object' && value !== null) {
|
|
320
|
-
if (seen.has(value)) {
|
|
321
|
-
throw new UnexpectedError(`${name} has circular reference`);
|
|
322
|
-
}
|
|
323
|
-
seen.add(value);
|
|
324
|
-
if (Array.isArray(value)) {
|
|
325
|
-
stack.push(...value.map((value) => ({ value })));
|
|
326
|
-
} else {
|
|
327
|
-
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
*/
|
|
332
|
-
return;
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
else {
|
|
336
|
-
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
/**
|
|
340
|
-
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
341
|
-
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
342
|
-
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
217
|
+
* @public exported from `@promptbook/core`
|
|
343
218
|
*/
|
|
344
|
-
|
|
219
|
+
var ADMIN_EMAIL = 'me@pavolhejny.com';
|
|
345
220
|
/**
|
|
346
|
-
*
|
|
347
|
-
* @@@
|
|
221
|
+
* Name of the responsible person for the Promptbook on GitHub
|
|
348
222
|
*
|
|
349
|
-
*
|
|
350
|
-
*
|
|
351
|
-
* @param name - Name of the object for debugging purposes
|
|
352
|
-
* @param objectValue - Object to be deeply frozen
|
|
353
|
-
* @returns The same object as the input, but deeply frozen
|
|
354
|
-
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
355
|
-
*/
|
|
356
|
-
function $asDeeplyFrozenSerializableJson(name, objectValue) {
|
|
357
|
-
checkSerializableAsJson(name, objectValue);
|
|
358
|
-
return $deepFreeze(objectValue);
|
|
359
|
-
}
|
|
360
|
-
/**
|
|
361
|
-
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
362
|
-
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
223
|
+
* @public exported from `@promptbook/core`
|
|
363
224
|
*/
|
|
364
|
-
|
|
225
|
+
var ADMIN_GITHUB_NAME = 'hejny';
|
|
365
226
|
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
366
227
|
/**
|
|
367
228
|
* The maximum number of iterations for a loops
|
|
@@ -413,7 +274,8 @@ var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
|
413
274
|
*
|
|
414
275
|
* @public exported from `@promptbook/core`
|
|
415
276
|
*/
|
|
416
|
-
var RESERVED_PARAMETER_NAMES =
|
|
277
|
+
var RESERVED_PARAMETER_NAMES =
|
|
278
|
+
/* !!!!!! $asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', _____ as const); */ [
|
|
417
279
|
'content',
|
|
418
280
|
'context',
|
|
419
281
|
'knowledge',
|
|
@@ -423,7 +285,7 @@ var RESERVED_PARAMETER_NAMES = $asDeeplyFrozenSerializableJson('RESERVED_PARAMET
|
|
|
423
285
|
// <- TODO: list here all command names
|
|
424
286
|
// <- TODO: Add more like 'date', 'modelName',...
|
|
425
287
|
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
426
|
-
]
|
|
288
|
+
];
|
|
427
289
|
/**
|
|
428
290
|
* @@@
|
|
429
291
|
*
|
|
@@ -491,6 +353,40 @@ var NotYetImplementedError = /** @class */ (function (_super) {
|
|
|
491
353
|
return NotYetImplementedError;
|
|
492
354
|
}(Error));
|
|
493
355
|
|
|
356
|
+
/**
|
|
357
|
+
* Make error report URL for the given error
|
|
358
|
+
*
|
|
359
|
+
* @private !!!!!!
|
|
360
|
+
*/
|
|
361
|
+
function getErrorReportUrl(error) {
|
|
362
|
+
var report = {
|
|
363
|
+
title: "\uD83D\uDC1C Error report from ".concat(NAME),
|
|
364
|
+
body: spaceTrim$1(function (block) { return "\n\n\n `".concat(error.name || 'Error', "` has occurred in the [").concat(NAME, "], please look into it @").concat(ADMIN_GITHUB_NAME, ".\n\n ```\n ").concat(block(error.message || '(no error message)'), "\n ```\n\n\n ## More info:\n\n - **Promptbook engine version:** ").concat(PROMPTBOOK_ENGINE_VERSION, "\n - **Book language version:** ").concat(BOOK_LANGUAGE_VERSION, "\n - **Time:** ").concat(new Date().toISOString(), "\n\n <details>\n <summary>Stack trace:</summary>\n\n ## Stack trace:\n\n ```stacktrace\n ").concat(block(error.stack || '(empty)'), "\n ```\n </details>\n\n "); }),
|
|
365
|
+
};
|
|
366
|
+
var reportUrl = new URL("https://github.com/webgptorg/promptbook/issues/new");
|
|
367
|
+
reportUrl.searchParams.set('labels', 'bug');
|
|
368
|
+
reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
|
|
369
|
+
reportUrl.searchParams.set('title', report.title);
|
|
370
|
+
reportUrl.searchParams.set('body', report.body);
|
|
371
|
+
return reportUrl;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
376
|
+
*
|
|
377
|
+
* @public exported from `@promptbook/core`
|
|
378
|
+
*/
|
|
379
|
+
var UnexpectedError = /** @class */ (function (_super) {
|
|
380
|
+
__extends(UnexpectedError, _super);
|
|
381
|
+
function UnexpectedError(message) {
|
|
382
|
+
var _this = _super.call(this, spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the pipeline collection\n\n Please report issue:\n ").concat(block(getErrorReportUrl(new Error(message)).href), "\n\n Or contact us on ").concat(ADMIN_EMAIL, "\n\n "); })) || this;
|
|
383
|
+
_this.name = 'UnexpectedError';
|
|
384
|
+
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
385
|
+
return _this;
|
|
386
|
+
}
|
|
387
|
+
return UnexpectedError;
|
|
388
|
+
}(Error));
|
|
389
|
+
|
|
494
390
|
/**
|
|
495
391
|
* @@@
|
|
496
392
|
*
|
|
@@ -702,32 +598,12 @@ var KnowledgeScrapeError = /** @class */ (function (_super) {
|
|
|
702
598
|
}(Error));
|
|
703
599
|
|
|
704
600
|
/**
|
|
705
|
-
*
|
|
706
|
-
*
|
|
707
|
-
* Note: Dataurl are considered perfectly valid.
|
|
708
|
-
* Note: There are two simmilar functions:
|
|
709
|
-
* - `isValidUrl` which tests any URL
|
|
710
|
-
* - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
|
|
601
|
+
* @@@
|
|
711
602
|
*
|
|
712
|
-
* @
|
|
603
|
+
* @private for `FileCacheStorage`
|
|
713
604
|
*/
|
|
714
|
-
function
|
|
715
|
-
|
|
716
|
-
return false;
|
|
717
|
-
}
|
|
718
|
-
try {
|
|
719
|
-
if (url.startsWith('blob:')) {
|
|
720
|
-
url = url.replace(/^blob:/, '');
|
|
721
|
-
}
|
|
722
|
-
var urlObject = new URL(url /* because fail is handled */);
|
|
723
|
-
if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
|
|
724
|
-
return false;
|
|
725
|
-
}
|
|
726
|
-
return true;
|
|
727
|
-
}
|
|
728
|
-
catch (error) {
|
|
729
|
-
return false;
|
|
730
|
-
}
|
|
605
|
+
function nameToSubfolderPath(name) {
|
|
606
|
+
return [name.substr(0, 1).toLowerCase(), name.substr(1, 1).toLowerCase()];
|
|
731
607
|
}
|
|
732
608
|
|
|
733
609
|
var defaultDiacriticsRemovalMap = [
|
|
@@ -1095,6 +971,35 @@ function isValidFilePath(filename) {
|
|
|
1095
971
|
return false;
|
|
1096
972
|
}
|
|
1097
973
|
|
|
974
|
+
/**
|
|
975
|
+
* Tests if given string is valid URL.
|
|
976
|
+
*
|
|
977
|
+
* Note: Dataurl are considered perfectly valid.
|
|
978
|
+
* Note: There are two simmilar functions:
|
|
979
|
+
* - `isValidUrl` which tests any URL
|
|
980
|
+
* - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
|
|
981
|
+
*
|
|
982
|
+
* @public exported from `@promptbook/utils`
|
|
983
|
+
*/
|
|
984
|
+
function isValidUrl(url) {
|
|
985
|
+
if (typeof url !== 'string') {
|
|
986
|
+
return false;
|
|
987
|
+
}
|
|
988
|
+
try {
|
|
989
|
+
if (url.startsWith('blob:')) {
|
|
990
|
+
url = url.replace(/^blob:/, '');
|
|
991
|
+
}
|
|
992
|
+
var urlObject = new URL(url /* because fail is handled */);
|
|
993
|
+
if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
|
|
994
|
+
return false;
|
|
995
|
+
}
|
|
996
|
+
return true;
|
|
997
|
+
}
|
|
998
|
+
catch (error) {
|
|
999
|
+
return false;
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1098
1003
|
/**
|
|
1099
1004
|
* @@@
|
|
1100
1005
|
*
|
|
@@ -1119,15 +1024,6 @@ function titleToName(value) {
|
|
|
1119
1024
|
return value;
|
|
1120
1025
|
}
|
|
1121
1026
|
|
|
1122
|
-
/**
|
|
1123
|
-
* @@@
|
|
1124
|
-
*
|
|
1125
|
-
* @private for `FileCacheStorage`
|
|
1126
|
-
*/
|
|
1127
|
-
function nameToSubfolderPath(name) {
|
|
1128
|
-
return [name.substr(0, 1).toLowerCase(), name.substr(1, 1).toLowerCase()];
|
|
1129
|
-
}
|
|
1130
|
-
|
|
1131
1027
|
/**
|
|
1132
1028
|
* Create a filename for intermediate cache for scrapers
|
|
1133
1029
|
*
|
|
@@ -1936,6 +1832,149 @@ function extractParameterNames(template) {
|
|
|
1936
1832
|
return parameterNames;
|
|
1937
1833
|
}
|
|
1938
1834
|
|
|
1835
|
+
/**
|
|
1836
|
+
* Checks if the value is [🚉] serializable as JSON
|
|
1837
|
+
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
1838
|
+
*
|
|
1839
|
+
* - Almost all primitives are serializable BUT:
|
|
1840
|
+
* - `undefined` is not serializable
|
|
1841
|
+
* - `NaN` is not serializable
|
|
1842
|
+
* - Objects and arrays are serializable if all their properties are serializable
|
|
1843
|
+
* - Functions are not serializable
|
|
1844
|
+
* - Circular references are not serializable
|
|
1845
|
+
* - `Date` objects are not serializable
|
|
1846
|
+
* - `Map` and `Set` objects are not serializable
|
|
1847
|
+
* - `RegExp` objects are not serializable
|
|
1848
|
+
* - `Error` objects are not serializable
|
|
1849
|
+
* - `Symbol` objects are not serializable
|
|
1850
|
+
* - And much more...
|
|
1851
|
+
*
|
|
1852
|
+
* @throws UnexpectedError if the value is not serializable as JSON
|
|
1853
|
+
* @public exported from `@promptbook/utils`
|
|
1854
|
+
*/
|
|
1855
|
+
function checkSerializableAsJson(name, value) {
|
|
1856
|
+
var e_1, _a;
|
|
1857
|
+
if (value === undefined) {
|
|
1858
|
+
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
1859
|
+
}
|
|
1860
|
+
else if (value === null) {
|
|
1861
|
+
return;
|
|
1862
|
+
}
|
|
1863
|
+
else if (typeof value === 'boolean') {
|
|
1864
|
+
return;
|
|
1865
|
+
}
|
|
1866
|
+
else if (typeof value === 'number' && !isNaN(value)) {
|
|
1867
|
+
return;
|
|
1868
|
+
}
|
|
1869
|
+
else if (typeof value === 'string') {
|
|
1870
|
+
return;
|
|
1871
|
+
}
|
|
1872
|
+
else if (typeof value === 'symbol') {
|
|
1873
|
+
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
1874
|
+
}
|
|
1875
|
+
else if (typeof value === 'function') {
|
|
1876
|
+
throw new UnexpectedError("".concat(name, " is function"));
|
|
1877
|
+
}
|
|
1878
|
+
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
1879
|
+
for (var i = 0; i < value.length; i++) {
|
|
1880
|
+
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
1881
|
+
}
|
|
1882
|
+
}
|
|
1883
|
+
else if (typeof value === 'object') {
|
|
1884
|
+
if (value instanceof Date) {
|
|
1885
|
+
throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
1886
|
+
}
|
|
1887
|
+
else if (value instanceof Map) {
|
|
1888
|
+
throw new UnexpectedError("".concat(name, " is Map"));
|
|
1889
|
+
}
|
|
1890
|
+
else if (value instanceof Set) {
|
|
1891
|
+
throw new UnexpectedError("".concat(name, " is Set"));
|
|
1892
|
+
}
|
|
1893
|
+
else if (value instanceof RegExp) {
|
|
1894
|
+
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
1895
|
+
}
|
|
1896
|
+
else if (value instanceof Error) {
|
|
1897
|
+
throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
1898
|
+
}
|
|
1899
|
+
else {
|
|
1900
|
+
try {
|
|
1901
|
+
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1902
|
+
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
1903
|
+
if (subValue === undefined) {
|
|
1904
|
+
// Note: undefined in object is serializable - it is just omited
|
|
1905
|
+
continue;
|
|
1906
|
+
}
|
|
1907
|
+
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1910
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1911
|
+
finally {
|
|
1912
|
+
try {
|
|
1913
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1914
|
+
}
|
|
1915
|
+
finally { if (e_1) throw e_1.error; }
|
|
1916
|
+
}
|
|
1917
|
+
try {
|
|
1918
|
+
JSON.stringify(value); // <- TODO: [0]
|
|
1919
|
+
}
|
|
1920
|
+
catch (error) {
|
|
1921
|
+
if (!(error instanceof Error)) {
|
|
1922
|
+
throw error;
|
|
1923
|
+
}
|
|
1924
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
1925
|
+
}
|
|
1926
|
+
/*
|
|
1927
|
+
TODO: [0] Is there some more elegant way to check circular references?
|
|
1928
|
+
const seen = new Set();
|
|
1929
|
+
const stack = [{ value }];
|
|
1930
|
+
while (stack.length > 0) {
|
|
1931
|
+
const { value } = stack.pop()!;
|
|
1932
|
+
if (typeof value === 'object' && value !== null) {
|
|
1933
|
+
if (seen.has(value)) {
|
|
1934
|
+
throw new UnexpectedError(`${name} has circular reference`);
|
|
1935
|
+
}
|
|
1936
|
+
seen.add(value);
|
|
1937
|
+
if (Array.isArray(value)) {
|
|
1938
|
+
stack.push(...value.map((value) => ({ value })));
|
|
1939
|
+
} else {
|
|
1940
|
+
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
*/
|
|
1945
|
+
return;
|
|
1946
|
+
}
|
|
1947
|
+
}
|
|
1948
|
+
else {
|
|
1949
|
+
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
1950
|
+
}
|
|
1951
|
+
}
|
|
1952
|
+
/**
|
|
1953
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
1954
|
+
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
1955
|
+
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
1956
|
+
*/
|
|
1957
|
+
|
|
1958
|
+
/**
|
|
1959
|
+
* @@@
|
|
1960
|
+
* @@@
|
|
1961
|
+
*
|
|
1962
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
1963
|
+
*
|
|
1964
|
+
* @param name - Name of the object for debugging purposes
|
|
1965
|
+
* @param objectValue - Object to be deeply frozen
|
|
1966
|
+
* @returns The same object as the input, but deeply frozen
|
|
1967
|
+
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
1968
|
+
*/
|
|
1969
|
+
function $asDeeplyFrozenSerializableJson(name, objectValue) {
|
|
1970
|
+
checkSerializableAsJson(name, objectValue);
|
|
1971
|
+
return $deepFreeze(objectValue);
|
|
1972
|
+
}
|
|
1973
|
+
/**
|
|
1974
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
1975
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
1976
|
+
*/
|
|
1977
|
+
|
|
1939
1978
|
/**
|
|
1940
1979
|
* Unprepare just strips the preparation data of the pipeline
|
|
1941
1980
|
*
|
|
@@ -3697,10 +3736,11 @@ function preparePipeline(pipeline, tools, options) {
|
|
|
3697
3736
|
* @param script from which to extract the variables
|
|
3698
3737
|
* @returns the list of variable names
|
|
3699
3738
|
* @throws {ParseError} if the script is invalid
|
|
3700
|
-
* @public exported from `@promptbook/utils`
|
|
3739
|
+
* @public exported from `@promptbook/utils` <- Note: [👖] This is usable elsewhere than in Promptbook, so keeping in utils
|
|
3701
3740
|
*/
|
|
3702
|
-
function
|
|
3741
|
+
function extractVariablesFromScript(script) {
|
|
3703
3742
|
var variables = new Set();
|
|
3743
|
+
var originalScript = script;
|
|
3704
3744
|
script = "(()=>{".concat(script, "})()");
|
|
3705
3745
|
try {
|
|
3706
3746
|
for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
|
|
@@ -3732,7 +3772,9 @@ function extractVariables(script) {
|
|
|
3732
3772
|
if (!(error instanceof Error)) {
|
|
3733
3773
|
throw error;
|
|
3734
3774
|
}
|
|
3735
|
-
throw new ParseError(spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n
|
|
3775
|
+
throw new ParseError(spaceTrim(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)
|
|
3776
|
+
.map(function (variableName, i) { return "".concat(i + 1, ") ").concat(variableName); })
|
|
3777
|
+
.join('\n'), "\n\n\n The script:\n\n ```javascript\n ").concat(block(originalScript), "\n ```\n "); }));
|
|
3736
3778
|
}
|
|
3737
3779
|
return variables;
|
|
3738
3780
|
}
|
|
@@ -3746,7 +3788,7 @@ function extractVariables(script) {
|
|
|
3746
3788
|
* @param task the task with used parameters
|
|
3747
3789
|
* @returns the set of parameter names
|
|
3748
3790
|
* @throws {ParseError} if the script is invalid
|
|
3749
|
-
* @public exported from `@promptbook/
|
|
3791
|
+
* @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
|
|
3750
3792
|
*/
|
|
3751
3793
|
function extractParameterNamesFromTask(task) {
|
|
3752
3794
|
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
@@ -3767,7 +3809,7 @@ function extractParameterNamesFromTask(task) {
|
|
|
3767
3809
|
}
|
|
3768
3810
|
if (taskType === 'SCRIPT_TASK') {
|
|
3769
3811
|
try {
|
|
3770
|
-
for (var _g = __values(
|
|
3812
|
+
for (var _g = __values(extractVariablesFromScript(content)), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
3771
3813
|
var parameterName = _h.value;
|
|
3772
3814
|
parameterNames.add(parameterName);
|
|
3773
3815
|
}
|