@promptbook/node 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 +377 -334
- 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 +238 -195
- 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
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
*
|
|
44
44
|
* @see https://github.com/webgptorg/promptbook
|
|
45
45
|
*/
|
|
46
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.
|
|
46
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.78.1';
|
|
47
47
|
/**
|
|
48
48
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
49
49
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -189,198 +189,25 @@
|
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
/**
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
195
|
-
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
192
|
+
* Name for the Promptbook
|
|
196
193
|
*
|
|
197
|
-
*
|
|
198
|
-
* @public exported from `@promptbook/utils`
|
|
199
|
-
*/
|
|
200
|
-
function $deepFreeze(objectValue) {
|
|
201
|
-
var e_1, _a;
|
|
202
|
-
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
203
|
-
try {
|
|
204
|
-
for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
|
|
205
|
-
var propertyName = propertyNames_1_1.value;
|
|
206
|
-
var value = objectValue[propertyName];
|
|
207
|
-
if (value && typeof value === 'object') {
|
|
208
|
-
$deepFreeze(value);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
213
|
-
finally {
|
|
214
|
-
try {
|
|
215
|
-
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
216
|
-
}
|
|
217
|
-
finally { if (e_1) throw e_1.error; }
|
|
218
|
-
}
|
|
219
|
-
return Object.freeze(objectValue);
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
223
|
-
*/
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
194
|
+
* TODO: [🗽] Unite branding and make single place for it
|
|
227
195
|
*
|
|
228
196
|
* @public exported from `@promptbook/core`
|
|
229
197
|
*/
|
|
230
|
-
var
|
|
231
|
-
__extends(UnexpectedError, _super);
|
|
232
|
-
function UnexpectedError(message) {
|
|
233
|
-
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;
|
|
234
|
-
_this.name = 'UnexpectedError';
|
|
235
|
-
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
236
|
-
return _this;
|
|
237
|
-
}
|
|
238
|
-
return UnexpectedError;
|
|
239
|
-
}(Error));
|
|
240
|
-
|
|
198
|
+
var NAME = "Promptbook";
|
|
241
199
|
/**
|
|
242
|
-
*
|
|
243
|
-
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
244
|
-
*
|
|
245
|
-
* - Almost all primitives are serializable BUT:
|
|
246
|
-
* - `undefined` is not serializable
|
|
247
|
-
* - `NaN` is not serializable
|
|
248
|
-
* - Objects and arrays are serializable if all their properties are serializable
|
|
249
|
-
* - Functions are not serializable
|
|
250
|
-
* - Circular references are not serializable
|
|
251
|
-
* - `Date` objects are not serializable
|
|
252
|
-
* - `Map` and `Set` objects are not serializable
|
|
253
|
-
* - `RegExp` objects are not serializable
|
|
254
|
-
* - `Error` objects are not serializable
|
|
255
|
-
* - `Symbol` objects are not serializable
|
|
256
|
-
* - And much more...
|
|
200
|
+
* Email of the responsible person
|
|
257
201
|
*
|
|
258
|
-
* @
|
|
259
|
-
* @public exported from `@promptbook/utils`
|
|
260
|
-
*/
|
|
261
|
-
function checkSerializableAsJson(name, value) {
|
|
262
|
-
var e_1, _a;
|
|
263
|
-
if (value === undefined) {
|
|
264
|
-
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
265
|
-
}
|
|
266
|
-
else if (value === null) {
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
else if (typeof value === 'boolean') {
|
|
270
|
-
return;
|
|
271
|
-
}
|
|
272
|
-
else if (typeof value === 'number' && !isNaN(value)) {
|
|
273
|
-
return;
|
|
274
|
-
}
|
|
275
|
-
else if (typeof value === 'string') {
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
else if (typeof value === 'symbol') {
|
|
279
|
-
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
280
|
-
}
|
|
281
|
-
else if (typeof value === 'function') {
|
|
282
|
-
throw new UnexpectedError("".concat(name, " is function"));
|
|
283
|
-
}
|
|
284
|
-
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
285
|
-
for (var i = 0; i < value.length; i++) {
|
|
286
|
-
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
else if (typeof value === 'object') {
|
|
290
|
-
if (value instanceof Date) {
|
|
291
|
-
throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
292
|
-
}
|
|
293
|
-
else if (value instanceof Map) {
|
|
294
|
-
throw new UnexpectedError("".concat(name, " is Map"));
|
|
295
|
-
}
|
|
296
|
-
else if (value instanceof Set) {
|
|
297
|
-
throw new UnexpectedError("".concat(name, " is Set"));
|
|
298
|
-
}
|
|
299
|
-
else if (value instanceof RegExp) {
|
|
300
|
-
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
301
|
-
}
|
|
302
|
-
else if (value instanceof Error) {
|
|
303
|
-
throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
304
|
-
}
|
|
305
|
-
else {
|
|
306
|
-
try {
|
|
307
|
-
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
308
|
-
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
309
|
-
if (subValue === undefined) {
|
|
310
|
-
// Note: undefined in object is serializable - it is just omited
|
|
311
|
-
continue;
|
|
312
|
-
}
|
|
313
|
-
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
317
|
-
finally {
|
|
318
|
-
try {
|
|
319
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
320
|
-
}
|
|
321
|
-
finally { if (e_1) throw e_1.error; }
|
|
322
|
-
}
|
|
323
|
-
try {
|
|
324
|
-
JSON.stringify(value); // <- TODO: [0]
|
|
325
|
-
}
|
|
326
|
-
catch (error) {
|
|
327
|
-
if (!(error instanceof Error)) {
|
|
328
|
-
throw error;
|
|
329
|
-
}
|
|
330
|
-
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
331
|
-
}
|
|
332
|
-
/*
|
|
333
|
-
TODO: [0] Is there some more elegant way to check circular references?
|
|
334
|
-
const seen = new Set();
|
|
335
|
-
const stack = [{ value }];
|
|
336
|
-
while (stack.length > 0) {
|
|
337
|
-
const { value } = stack.pop()!;
|
|
338
|
-
if (typeof value === 'object' && value !== null) {
|
|
339
|
-
if (seen.has(value)) {
|
|
340
|
-
throw new UnexpectedError(`${name} has circular reference`);
|
|
341
|
-
}
|
|
342
|
-
seen.add(value);
|
|
343
|
-
if (Array.isArray(value)) {
|
|
344
|
-
stack.push(...value.map((value) => ({ value })));
|
|
345
|
-
} else {
|
|
346
|
-
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
*/
|
|
351
|
-
return;
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
else {
|
|
355
|
-
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
/**
|
|
359
|
-
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
360
|
-
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
361
|
-
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
202
|
+
* @public exported from `@promptbook/core`
|
|
362
203
|
*/
|
|
363
|
-
|
|
204
|
+
var ADMIN_EMAIL = 'me@pavolhejny.com';
|
|
364
205
|
/**
|
|
365
|
-
*
|
|
366
|
-
* @@@
|
|
367
|
-
*
|
|
368
|
-
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
206
|
+
* Name of the responsible person for the Promptbook on GitHub
|
|
369
207
|
*
|
|
370
|
-
* @
|
|
371
|
-
* @param objectValue - Object to be deeply frozen
|
|
372
|
-
* @returns The same object as the input, but deeply frozen
|
|
373
|
-
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
374
|
-
*/
|
|
375
|
-
function $asDeeplyFrozenSerializableJson(name, objectValue) {
|
|
376
|
-
checkSerializableAsJson(name, objectValue);
|
|
377
|
-
return $deepFreeze(objectValue);
|
|
378
|
-
}
|
|
379
|
-
/**
|
|
380
|
-
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
381
|
-
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
208
|
+
* @public exported from `@promptbook/core`
|
|
382
209
|
*/
|
|
383
|
-
|
|
210
|
+
var ADMIN_GITHUB_NAME = 'hejny';
|
|
384
211
|
/**
|
|
385
212
|
* When the title is not provided, the default title is used
|
|
386
213
|
*
|
|
@@ -450,7 +277,8 @@
|
|
|
450
277
|
*
|
|
451
278
|
* @public exported from `@promptbook/core`
|
|
452
279
|
*/
|
|
453
|
-
var RESERVED_PARAMETER_NAMES =
|
|
280
|
+
var RESERVED_PARAMETER_NAMES =
|
|
281
|
+
/* !!!!!! $asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', _____ as const); */ [
|
|
454
282
|
'content',
|
|
455
283
|
'context',
|
|
456
284
|
'knowledge',
|
|
@@ -460,7 +288,7 @@
|
|
|
460
288
|
// <- TODO: list here all command names
|
|
461
289
|
// <- TODO: Add more like 'date', 'modelName',...
|
|
462
290
|
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
463
|
-
]
|
|
291
|
+
];
|
|
464
292
|
/**
|
|
465
293
|
* @@@
|
|
466
294
|
*
|
|
@@ -853,6 +681,40 @@
|
|
|
853
681
|
});
|
|
854
682
|
}
|
|
855
683
|
|
|
684
|
+
/**
|
|
685
|
+
* @@@
|
|
686
|
+
*
|
|
687
|
+
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
688
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
689
|
+
*
|
|
690
|
+
* @returns The same object as the input, but deeply frozen
|
|
691
|
+
* @public exported from `@promptbook/utils`
|
|
692
|
+
*/
|
|
693
|
+
function $deepFreeze(objectValue) {
|
|
694
|
+
var e_1, _a;
|
|
695
|
+
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
696
|
+
try {
|
|
697
|
+
for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
|
|
698
|
+
var propertyName = propertyNames_1_1.value;
|
|
699
|
+
var value = objectValue[propertyName];
|
|
700
|
+
if (value && typeof value === 'object') {
|
|
701
|
+
$deepFreeze(value);
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
706
|
+
finally {
|
|
707
|
+
try {
|
|
708
|
+
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
709
|
+
}
|
|
710
|
+
finally { if (e_1) throw e_1.error; }
|
|
711
|
+
}
|
|
712
|
+
return Object.freeze(objectValue);
|
|
713
|
+
}
|
|
714
|
+
/**
|
|
715
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
716
|
+
*/
|
|
717
|
+
|
|
856
718
|
/**
|
|
857
719
|
* Represents the usage with no resources consumed
|
|
858
720
|
*
|
|
@@ -1107,6 +969,40 @@
|
|
|
1107
969
|
return PipelineExecutionError;
|
|
1108
970
|
}(Error));
|
|
1109
971
|
|
|
972
|
+
/**
|
|
973
|
+
* Make error report URL for the given error
|
|
974
|
+
*
|
|
975
|
+
* @private !!!!!!
|
|
976
|
+
*/
|
|
977
|
+
function getErrorReportUrl(error) {
|
|
978
|
+
var report = {
|
|
979
|
+
title: "\uD83D\uDC1C Error report from ".concat(NAME),
|
|
980
|
+
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 "); }),
|
|
981
|
+
};
|
|
982
|
+
var reportUrl = new URL("https://github.com/webgptorg/promptbook/issues/new");
|
|
983
|
+
reportUrl.searchParams.set('labels', 'bug');
|
|
984
|
+
reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
|
|
985
|
+
reportUrl.searchParams.set('title', report.title);
|
|
986
|
+
reportUrl.searchParams.set('body', report.body);
|
|
987
|
+
return reportUrl;
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
/**
|
|
991
|
+
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
992
|
+
*
|
|
993
|
+
* @public exported from `@promptbook/core`
|
|
994
|
+
*/
|
|
995
|
+
var UnexpectedError = /** @class */ (function (_super) {
|
|
996
|
+
__extends(UnexpectedError, _super);
|
|
997
|
+
function UnexpectedError(message) {
|
|
998
|
+
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;
|
|
999
|
+
_this.name = 'UnexpectedError';
|
|
1000
|
+
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
1001
|
+
return _this;
|
|
1002
|
+
}
|
|
1003
|
+
return UnexpectedError;
|
|
1004
|
+
}(Error));
|
|
1005
|
+
|
|
1110
1006
|
/**
|
|
1111
1007
|
* Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
|
|
1112
1008
|
*
|
|
@@ -1916,6 +1812,149 @@
|
|
|
1916
1812
|
return parameterNames;
|
|
1917
1813
|
}
|
|
1918
1814
|
|
|
1815
|
+
/**
|
|
1816
|
+
* Checks if the value is [🚉] serializable as JSON
|
|
1817
|
+
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
1818
|
+
*
|
|
1819
|
+
* - Almost all primitives are serializable BUT:
|
|
1820
|
+
* - `undefined` is not serializable
|
|
1821
|
+
* - `NaN` is not serializable
|
|
1822
|
+
* - Objects and arrays are serializable if all their properties are serializable
|
|
1823
|
+
* - Functions are not serializable
|
|
1824
|
+
* - Circular references are not serializable
|
|
1825
|
+
* - `Date` objects are not serializable
|
|
1826
|
+
* - `Map` and `Set` objects are not serializable
|
|
1827
|
+
* - `RegExp` objects are not serializable
|
|
1828
|
+
* - `Error` objects are not serializable
|
|
1829
|
+
* - `Symbol` objects are not serializable
|
|
1830
|
+
* - And much more...
|
|
1831
|
+
*
|
|
1832
|
+
* @throws UnexpectedError if the value is not serializable as JSON
|
|
1833
|
+
* @public exported from `@promptbook/utils`
|
|
1834
|
+
*/
|
|
1835
|
+
function checkSerializableAsJson(name, value) {
|
|
1836
|
+
var e_1, _a;
|
|
1837
|
+
if (value === undefined) {
|
|
1838
|
+
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
1839
|
+
}
|
|
1840
|
+
else if (value === null) {
|
|
1841
|
+
return;
|
|
1842
|
+
}
|
|
1843
|
+
else if (typeof value === 'boolean') {
|
|
1844
|
+
return;
|
|
1845
|
+
}
|
|
1846
|
+
else if (typeof value === 'number' && !isNaN(value)) {
|
|
1847
|
+
return;
|
|
1848
|
+
}
|
|
1849
|
+
else if (typeof value === 'string') {
|
|
1850
|
+
return;
|
|
1851
|
+
}
|
|
1852
|
+
else if (typeof value === 'symbol') {
|
|
1853
|
+
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
1854
|
+
}
|
|
1855
|
+
else if (typeof value === 'function') {
|
|
1856
|
+
throw new UnexpectedError("".concat(name, " is function"));
|
|
1857
|
+
}
|
|
1858
|
+
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
1859
|
+
for (var i = 0; i < value.length; i++) {
|
|
1860
|
+
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1863
|
+
else if (typeof value === 'object') {
|
|
1864
|
+
if (value instanceof Date) {
|
|
1865
|
+
throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
1866
|
+
}
|
|
1867
|
+
else if (value instanceof Map) {
|
|
1868
|
+
throw new UnexpectedError("".concat(name, " is Map"));
|
|
1869
|
+
}
|
|
1870
|
+
else if (value instanceof Set) {
|
|
1871
|
+
throw new UnexpectedError("".concat(name, " is Set"));
|
|
1872
|
+
}
|
|
1873
|
+
else if (value instanceof RegExp) {
|
|
1874
|
+
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
1875
|
+
}
|
|
1876
|
+
else if (value instanceof Error) {
|
|
1877
|
+
throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
1878
|
+
}
|
|
1879
|
+
else {
|
|
1880
|
+
try {
|
|
1881
|
+
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1882
|
+
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
1883
|
+
if (subValue === undefined) {
|
|
1884
|
+
// Note: undefined in object is serializable - it is just omited
|
|
1885
|
+
continue;
|
|
1886
|
+
}
|
|
1887
|
+
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1891
|
+
finally {
|
|
1892
|
+
try {
|
|
1893
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1894
|
+
}
|
|
1895
|
+
finally { if (e_1) throw e_1.error; }
|
|
1896
|
+
}
|
|
1897
|
+
try {
|
|
1898
|
+
JSON.stringify(value); // <- TODO: [0]
|
|
1899
|
+
}
|
|
1900
|
+
catch (error) {
|
|
1901
|
+
if (!(error instanceof Error)) {
|
|
1902
|
+
throw error;
|
|
1903
|
+
}
|
|
1904
|
+
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
1905
|
+
}
|
|
1906
|
+
/*
|
|
1907
|
+
TODO: [0] Is there some more elegant way to check circular references?
|
|
1908
|
+
const seen = new Set();
|
|
1909
|
+
const stack = [{ value }];
|
|
1910
|
+
while (stack.length > 0) {
|
|
1911
|
+
const { value } = stack.pop()!;
|
|
1912
|
+
if (typeof value === 'object' && value !== null) {
|
|
1913
|
+
if (seen.has(value)) {
|
|
1914
|
+
throw new UnexpectedError(`${name} has circular reference`);
|
|
1915
|
+
}
|
|
1916
|
+
seen.add(value);
|
|
1917
|
+
if (Array.isArray(value)) {
|
|
1918
|
+
stack.push(...value.map((value) => ({ value })));
|
|
1919
|
+
} else {
|
|
1920
|
+
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1923
|
+
}
|
|
1924
|
+
*/
|
|
1925
|
+
return;
|
|
1926
|
+
}
|
|
1927
|
+
}
|
|
1928
|
+
else {
|
|
1929
|
+
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
/**
|
|
1933
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
1934
|
+
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
1935
|
+
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
1936
|
+
*/
|
|
1937
|
+
|
|
1938
|
+
/**
|
|
1939
|
+
* @@@
|
|
1940
|
+
* @@@
|
|
1941
|
+
*
|
|
1942
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
1943
|
+
*
|
|
1944
|
+
* @param name - Name of the object for debugging purposes
|
|
1945
|
+
* @param objectValue - Object to be deeply frozen
|
|
1946
|
+
* @returns The same object as the input, but deeply frozen
|
|
1947
|
+
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
1948
|
+
*/
|
|
1949
|
+
function $asDeeplyFrozenSerializableJson(name, objectValue) {
|
|
1950
|
+
checkSerializableAsJson(name, objectValue);
|
|
1951
|
+
return $deepFreeze(objectValue);
|
|
1952
|
+
}
|
|
1953
|
+
/**
|
|
1954
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
1955
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
1956
|
+
*/
|
|
1957
|
+
|
|
1919
1958
|
/**
|
|
1920
1959
|
* Unprepare just strips the preparation data of the pipeline
|
|
1921
1960
|
*
|
|
@@ -2337,10 +2376,11 @@
|
|
|
2337
2376
|
* @param script from which to extract the variables
|
|
2338
2377
|
* @returns the list of variable names
|
|
2339
2378
|
* @throws {ParseError} if the script is invalid
|
|
2340
|
-
* @public exported from `@promptbook/utils`
|
|
2379
|
+
* @public exported from `@promptbook/utils` <- Note: [👖] This is usable elsewhere than in Promptbook, so keeping in utils
|
|
2341
2380
|
*/
|
|
2342
|
-
function
|
|
2381
|
+
function extractVariablesFromScript(script) {
|
|
2343
2382
|
var variables = new Set();
|
|
2383
|
+
var originalScript = script;
|
|
2344
2384
|
script = "(()=>{".concat(script, "})()");
|
|
2345
2385
|
try {
|
|
2346
2386
|
for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
|
|
@@ -2372,7 +2412,9 @@
|
|
|
2372
2412
|
if (!(error instanceof Error)) {
|
|
2373
2413
|
throw error;
|
|
2374
2414
|
}
|
|
2375
|
-
throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n
|
|
2415
|
+
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)
|
|
2416
|
+
.map(function (variableName, i) { return "".concat(i + 1, ") ").concat(variableName); })
|
|
2417
|
+
.join('\n'), "\n\n\n The script:\n\n ```javascript\n ").concat(block(originalScript), "\n ```\n "); }));
|
|
2376
2418
|
}
|
|
2377
2419
|
return variables;
|
|
2378
2420
|
}
|
|
@@ -2386,7 +2428,7 @@
|
|
|
2386
2428
|
* @param task the task with used parameters
|
|
2387
2429
|
* @returns the set of parameter names
|
|
2388
2430
|
* @throws {ParseError} if the script is invalid
|
|
2389
|
-
* @public exported from `@promptbook/
|
|
2431
|
+
* @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
|
|
2390
2432
|
*/
|
|
2391
2433
|
function extractParameterNamesFromTask(task) {
|
|
2392
2434
|
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
@@ -2407,7 +2449,7 @@
|
|
|
2407
2449
|
}
|
|
2408
2450
|
if (taskType === 'SCRIPT_TASK') {
|
|
2409
2451
|
try {
|
|
2410
|
-
for (var _g = __values(
|
|
2452
|
+
for (var _g = __values(extractVariablesFromScript(content)), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
2411
2453
|
var parameterName = _h.value;
|
|
2412
2454
|
parameterNames.add(parameterName);
|
|
2413
2455
|
}
|
|
@@ -5802,7 +5844,7 @@
|
|
|
5802
5844
|
throw new ParseError(spaceTrim__default["default"]("\n Section type is already defined in the section.\n It can be defined only once.\n "));
|
|
5803
5845
|
}
|
|
5804
5846
|
$taskJson.isSectionTypeSet = true;
|
|
5805
|
-
// TODO: [🍧] Rearrange better - but at bottom and unwrap from function
|
|
5847
|
+
// TODO: [🍧][💩] Rearrange better - but at bottom and unwrap from function
|
|
5806
5848
|
var expectResultingParameterName = function () {
|
|
5807
5849
|
if ($taskJson.resultingParameterName) {
|
|
5808
5850
|
return;
|
|
@@ -7104,7 +7146,7 @@
|
|
|
7104
7146
|
if ($pipelineJson.defaultModelRequirements[command.key] !== undefined) {
|
|
7105
7147
|
if ($pipelineJson.defaultModelRequirements[command.key] === command.value) {
|
|
7106
7148
|
console.warn("Multiple commands `MODEL ".concat(command.key, " ").concat(command.value, "` in the pipeline head"));
|
|
7107
|
-
// <- TODO: [🚎] Some better way how to get warnings from pipeline parsing / logic
|
|
7149
|
+
// <- TODO: [🚎][💩] Some better way how to get warnings from pipeline parsing / logic
|
|
7108
7150
|
}
|
|
7109
7151
|
else {
|
|
7110
7152
|
throw new ParseError(spaceTrim__default["default"]("\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 ")));
|
|
@@ -7739,7 +7781,7 @@
|
|
|
7739
7781
|
personaCommandParser,
|
|
7740
7782
|
foreachCommandParser,
|
|
7741
7783
|
boilerplateCommandParser, // <- TODO: !! Only in development, remove in production
|
|
7742
|
-
// <- 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
|
|
7784
|
+
// <- 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
|
|
7743
7785
|
];
|
|
7744
7786
|
/**
|
|
7745
7787
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -8035,6 +8077,7 @@
|
|
|
8035
8077
|
var e_1, _a;
|
|
8036
8078
|
var lines = markdown.split('\n');
|
|
8037
8079
|
var sections = [];
|
|
8080
|
+
// TODO: [🧽] DRY
|
|
8038
8081
|
var currentType = 'MARKDOWN';
|
|
8039
8082
|
var buffer = [];
|
|
8040
8083
|
var finishSection = function () {
|
|
@@ -9529,10 +9572,10 @@
|
|
|
9529
9572
|
return __generator(this, function (_a) {
|
|
9530
9573
|
switch (_a.label) {
|
|
9531
9574
|
case 0:
|
|
9532
|
-
// TODO: Change to `await forEver` or something better
|
|
9575
|
+
// TODO: [💩] Change to `await forEver` or something better
|
|
9533
9576
|
return [4 /*yield*/, waitasecond.forTime(100000000)];
|
|
9534
9577
|
case 1:
|
|
9535
|
-
// TODO: Change to `await forEver` or something better
|
|
9578
|
+
// TODO: [💩] Change to `await forEver` or something better
|
|
9536
9579
|
_a.sent();
|
|
9537
9580
|
_a.label = 2;
|
|
9538
9581
|
case 2:
|