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