@promptbook/vercel 0.79.0 → 0.80.0-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/esm/index.es.js +222 -143
- package/esm/index.es.js.map +1 -1
- package/esm/typings/books/index.d.ts +6 -6
- package/esm/typings/src/_packages/core.index.d.ts +4 -2
- package/esm/typings/src/_packages/types.index.d.ts +10 -0
- package/esm/typings/src/_packages/utils.index.d.ts +4 -0
- package/esm/typings/src/cli/cli-commands/runInteractiveChatbot.d.ts +32 -0
- package/esm/typings/src/commands/_common/types/CommandParser.d.ts +3 -0
- package/esm/typings/src/config.d.ts +0 -25
- package/esm/typings/src/constants.d.ts +35 -0
- package/esm/typings/src/conversion/pipelineJsonToString.d.ts +1 -0
- package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +1 -0
- package/esm/typings/src/high-level-abstractions/_common/HighLevelAbstraction.d.ts +20 -0
- package/esm/typings/src/high-level-abstractions/implicit-formfactor/ImplicitFormfactorHla.d.ts +10 -0
- package/esm/typings/src/high-level-abstractions/index.d.ts +44 -0
- package/esm/typings/src/high-level-abstractions/quick-chatbot/QuickChatbotHla.d.ts +10 -0
- package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -1
- package/esm/typings/src/prepare/prepareTasks.d.ts +1 -0
- package/esm/typings/src/types/typeAliases.d.ts +1 -1
- package/esm/typings/src/utils/normalization/orderJson.d.ts +21 -0
- package/esm/typings/src/utils/normalization/orderJson.test.d.ts +4 -0
- package/esm/typings/src/utils/organization/keepTypeImported.d.ts +9 -0
- package/esm/typings/src/utils/serialization/$deepFreeze.d.ts +1 -1
- package/esm/typings/src/utils/serialization/checkSerializableAsJson.d.ts +20 -2
- package/esm/typings/src/utils/serialization/deepClone.test.d.ts +1 -0
- package/esm/typings/src/utils/serialization/exportJson.d.ts +29 -0
- package/esm/typings/src/utils/serialization/isSerializableAsJson.d.ts +2 -1
- package/package.json +2 -2
- package/umd/index.umd.js +222 -143
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/utils/serialization/$asDeeplyFrozenSerializableJson.d.ts +0 -17
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Just says that the type is used but `organize-imports-cli` does not recognize it.
|
|
3
|
+
* [🤛] This is a workaround for the issue.
|
|
4
|
+
*
|
|
5
|
+
* @param value any values
|
|
6
|
+
* @returns void
|
|
7
|
+
* @private within the repository
|
|
8
|
+
*/
|
|
9
|
+
export declare function keepTypeImported<TTypeToKeep>(): void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ReadonlyDeep } from 'type-fest';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Freezes the given object and all its nested objects recursively
|
|
4
4
|
*
|
|
5
5
|
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
6
6
|
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
@@ -1,4 +1,22 @@
|
|
|
1
1
|
import type { string_name } from '../../types/typeAliases';
|
|
2
|
+
import type { really_unknown } from '../organization/really_unknown';
|
|
3
|
+
/**
|
|
4
|
+
* Options for the `checkSerializableAsJson` function
|
|
5
|
+
*/
|
|
6
|
+
export type CheckSerializableAsJsonOptions = {
|
|
7
|
+
/**
|
|
8
|
+
* Value to be checked
|
|
9
|
+
*/
|
|
10
|
+
value: really_unknown;
|
|
11
|
+
/**
|
|
12
|
+
* Semantic name of the value for debugging purposes
|
|
13
|
+
*/
|
|
14
|
+
name?: string_name;
|
|
15
|
+
/**
|
|
16
|
+
* Message alongside the value for debugging purposes
|
|
17
|
+
*/
|
|
18
|
+
message?: string;
|
|
19
|
+
};
|
|
2
20
|
/**
|
|
3
21
|
* Checks if the value is [🚉] serializable as JSON
|
|
4
22
|
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
@@ -19,9 +37,9 @@ import type { string_name } from '../../types/typeAliases';
|
|
|
19
37
|
* @throws UnexpectedError if the value is not serializable as JSON
|
|
20
38
|
* @public exported from `@promptbook/utils`
|
|
21
39
|
*/
|
|
22
|
-
export declare function checkSerializableAsJson(
|
|
40
|
+
export declare function checkSerializableAsJson(options: CheckSerializableAsJsonOptions): void;
|
|
23
41
|
/**
|
|
24
|
-
* TODO:
|
|
42
|
+
* TODO: Can be return type more type-safe? like `asserts options.value is JsonValue`
|
|
25
43
|
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
26
44
|
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
27
45
|
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { JsonArray, JsonObject } from 'type-fest';
|
|
2
|
+
import type { OrderJsonOptions } from '../normalization/orderJson';
|
|
3
|
+
import type { CheckSerializableAsJsonOptions } from './checkSerializableAsJson';
|
|
4
|
+
/**
|
|
5
|
+
* Options for the `$exportJson` function
|
|
6
|
+
*/
|
|
7
|
+
export type ExportJsonOptions<TObject> = CheckSerializableAsJsonOptions & Partial<Pick<OrderJsonOptions<TObject & (JsonObject | JsonArray)>, 'order'>> & {
|
|
8
|
+
/**
|
|
9
|
+
* Value to be checked, ordered and deeply frozen
|
|
10
|
+
*/
|
|
11
|
+
value: TObject;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Utility to export a JSON object from a function
|
|
15
|
+
*
|
|
16
|
+
* 1) Checks if the value is serializable as JSON
|
|
17
|
+
* 2) Makes a deep clone of the object
|
|
18
|
+
* 2) Orders the object properties
|
|
19
|
+
* 2) Deeply freezes the cloned object
|
|
20
|
+
*
|
|
21
|
+
* Note: This function does not mutates the given object
|
|
22
|
+
*
|
|
23
|
+
* @returns The same type of object as the input but read-only and re-ordered
|
|
24
|
+
* @public exported from `@promptbook/utils`
|
|
25
|
+
*/
|
|
26
|
+
export declare function exportJson<TObject>(options: ExportJsonOptions<TObject>): TObject;
|
|
27
|
+
/**
|
|
28
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
29
|
+
*/
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { JsonValue } from 'type-fest';
|
|
1
2
|
/**
|
|
2
3
|
* Tests if the value is [🚉] serializable as JSON
|
|
3
4
|
*
|
|
@@ -17,7 +18,7 @@
|
|
|
17
18
|
*
|
|
18
19
|
* @public exported from `@promptbook/utils`
|
|
19
20
|
*/
|
|
20
|
-
export declare function isSerializableAsJson(value: unknown):
|
|
21
|
+
export declare function isSerializableAsJson(value: unknown): value is JsonValue;
|
|
21
22
|
/**
|
|
22
23
|
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
23
24
|
* TODO: [🧠][💺] Can be done this on type-level?
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/vercel",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.80.0-0",
|
|
4
4
|
"description": "It's time for a paradigm shift. The future of software in plain English, French or Latin",
|
|
5
5
|
"--note-0": " <- [🐊]",
|
|
6
6
|
"private": false,
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"module": "./esm/index.es.js",
|
|
55
55
|
"typings": "./esm/typings/src/_packages/vercel.index.d.ts",
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"@promptbook/core": "0.
|
|
57
|
+
"@promptbook/core": "0.80.0-0"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"colors": "1.4.0",
|
package/umd/index.umd.js
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
*
|
|
22
22
|
* @see https://github.com/webgptorg/promptbook
|
|
23
23
|
*/
|
|
24
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.
|
|
24
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.79.0';
|
|
25
25
|
/**
|
|
26
26
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
27
27
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -163,7 +163,7 @@
|
|
|
163
163
|
}(Error));
|
|
164
164
|
|
|
165
165
|
/**
|
|
166
|
-
*
|
|
166
|
+
* Freezes the given object and all its nested objects recursively
|
|
167
167
|
*
|
|
168
168
|
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
169
169
|
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
@@ -193,7 +193,8 @@
|
|
|
193
193
|
}
|
|
194
194
|
finally { if (e_1) throw e_1.error; }
|
|
195
195
|
}
|
|
196
|
-
|
|
196
|
+
Object.freeze(objectValue);
|
|
197
|
+
return objectValue;
|
|
197
198
|
}
|
|
198
199
|
/**
|
|
199
200
|
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
@@ -294,24 +295,6 @@
|
|
|
294
295
|
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
295
296
|
*/
|
|
296
297
|
var LOOP_LIMIT = 1000;
|
|
297
|
-
/**
|
|
298
|
-
* Nonce which is used for replacing things in strings
|
|
299
|
-
*
|
|
300
|
-
* @private within the repository
|
|
301
|
-
*/
|
|
302
|
-
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
303
|
-
/**
|
|
304
|
-
* @@@
|
|
305
|
-
*
|
|
306
|
-
* @private within the repository
|
|
307
|
-
*/
|
|
308
|
-
var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
|
|
309
|
-
/**
|
|
310
|
-
* @@@
|
|
311
|
-
*
|
|
312
|
-
* @private within the repository
|
|
313
|
-
*/
|
|
314
|
-
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
315
298
|
// <- TODO: [🧜♂️]
|
|
316
299
|
/**
|
|
317
300
|
* @@@
|
|
@@ -325,26 +308,21 @@
|
|
|
325
308
|
skipEmptyLines: true,
|
|
326
309
|
});
|
|
327
310
|
/**
|
|
328
|
-
* TODO: Extract `constants.ts` from `config.ts`
|
|
329
311
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
330
312
|
* TODO: [🧠][🧜♂️] Maybe join remoteUrl and path into single value
|
|
331
313
|
*/
|
|
332
314
|
|
|
333
315
|
/**
|
|
334
|
-
*
|
|
316
|
+
* Orders JSON object by keys
|
|
335
317
|
*
|
|
336
|
-
* @
|
|
318
|
+
* @returns The same type of object as the input re-ordered
|
|
319
|
+
* @public exported from `@promptbook/utils`
|
|
337
320
|
*/
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
function
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
Object.setPrototypeOf(_this, LimitReachedError.prototype);
|
|
344
|
-
return _this;
|
|
345
|
-
}
|
|
346
|
-
return LimitReachedError;
|
|
347
|
-
}(Error));
|
|
321
|
+
function orderJson(options) {
|
|
322
|
+
var value = options.value, order = options.order;
|
|
323
|
+
var orderedValue = __assign(__assign({}, (order === undefined ? {} : Object.fromEntries(order.map(function (key) { return [key, undefined]; })))), value);
|
|
324
|
+
return orderedValue;
|
|
325
|
+
}
|
|
348
326
|
|
|
349
327
|
/**
|
|
350
328
|
* Make error report URL for the given error
|
|
@@ -380,85 +358,6 @@
|
|
|
380
358
|
return UnexpectedError;
|
|
381
359
|
}(Error));
|
|
382
360
|
|
|
383
|
-
/**
|
|
384
|
-
* Replaces parameters in template with values from parameters object
|
|
385
|
-
*
|
|
386
|
-
* @param template the template with parameters in {curly} braces
|
|
387
|
-
* @param parameters the object with parameters
|
|
388
|
-
* @returns the template with replaced parameters
|
|
389
|
-
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
390
|
-
* @public exported from `@promptbook/utils`
|
|
391
|
-
*/
|
|
392
|
-
function replaceParameters(template, parameters) {
|
|
393
|
-
var e_1, _a;
|
|
394
|
-
try {
|
|
395
|
-
for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
396
|
-
var _d = __read(_c.value, 2), parameterName = _d[0], parameterValue = _d[1];
|
|
397
|
-
if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
|
|
398
|
-
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` has missing value"));
|
|
399
|
-
}
|
|
400
|
-
else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
|
|
401
|
-
// TODO: [🍵]
|
|
402
|
-
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` is restricted to use"));
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
407
|
-
finally {
|
|
408
|
-
try {
|
|
409
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
410
|
-
}
|
|
411
|
-
finally { if (e_1) throw e_1.error; }
|
|
412
|
-
}
|
|
413
|
-
var replacedTemplates = template;
|
|
414
|
-
var match;
|
|
415
|
-
var loopLimit = LOOP_LIMIT;
|
|
416
|
-
var _loop_1 = function () {
|
|
417
|
-
if (loopLimit-- < 0) {
|
|
418
|
-
throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`');
|
|
419
|
-
}
|
|
420
|
-
var precol = match.groups.precol;
|
|
421
|
-
var parameterName = match.groups.parameterName;
|
|
422
|
-
if (parameterName === '') {
|
|
423
|
-
return "continue";
|
|
424
|
-
}
|
|
425
|
-
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
|
|
426
|
-
throw new PipelineExecutionError('Parameter is already opened or not closed');
|
|
427
|
-
}
|
|
428
|
-
if (parameters[parameterName] === undefined) {
|
|
429
|
-
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
|
|
430
|
-
}
|
|
431
|
-
var parameterValue = parameters[parameterName];
|
|
432
|
-
if (parameterValue === undefined) {
|
|
433
|
-
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
|
|
434
|
-
}
|
|
435
|
-
parameterValue = parameterValue.toString();
|
|
436
|
-
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
437
|
-
parameterValue = parameterValue
|
|
438
|
-
.split('\n')
|
|
439
|
-
.map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
|
|
440
|
-
.join('\n');
|
|
441
|
-
}
|
|
442
|
-
replacedTemplates =
|
|
443
|
-
replacedTemplates.substring(0, match.index + precol.length) +
|
|
444
|
-
parameterValue +
|
|
445
|
-
replacedTemplates.substring(match.index + precol.length + parameterName.length + 2);
|
|
446
|
-
};
|
|
447
|
-
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
|
|
448
|
-
.exec(replacedTemplates))) {
|
|
449
|
-
_loop_1();
|
|
450
|
-
}
|
|
451
|
-
// [💫] Check if there are parameters that are not closed properly
|
|
452
|
-
if (/{\w+$/.test(replacedTemplates)) {
|
|
453
|
-
throw new PipelineExecutionError('Parameter is not closed');
|
|
454
|
-
}
|
|
455
|
-
// [💫] Check if there are parameters that are not opened properly
|
|
456
|
-
if (/^\w+}/.test(replacedTemplates)) {
|
|
457
|
-
throw new PipelineExecutionError('Parameter is not opened');
|
|
458
|
-
}
|
|
459
|
-
return replacedTemplates;
|
|
460
|
-
}
|
|
461
|
-
|
|
462
361
|
/**
|
|
463
362
|
* Checks if the value is [🚉] serializable as JSON
|
|
464
363
|
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
@@ -479,8 +378,9 @@
|
|
|
479
378
|
* @throws UnexpectedError if the value is not serializable as JSON
|
|
480
379
|
* @public exported from `@promptbook/utils`
|
|
481
380
|
*/
|
|
482
|
-
function checkSerializableAsJson(
|
|
381
|
+
function checkSerializableAsJson(options) {
|
|
483
382
|
var e_1, _a;
|
|
383
|
+
var value = options.value, name = options.name, message = options.message;
|
|
484
384
|
if (value === undefined) {
|
|
485
385
|
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
486
386
|
}
|
|
@@ -504,12 +404,12 @@
|
|
|
504
404
|
}
|
|
505
405
|
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
506
406
|
for (var i = 0; i < value.length; i++) {
|
|
507
|
-
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
407
|
+
checkSerializableAsJson({ name: "".concat(name, "[").concat(i, "]"), value: value[i], message: message });
|
|
508
408
|
}
|
|
509
409
|
}
|
|
510
410
|
else if (typeof value === 'object') {
|
|
511
411
|
if (value instanceof Date) {
|
|
512
|
-
throw new UnexpectedError(spaceTrim__default["default"]("\n
|
|
412
|
+
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n `".concat(name, "` is Date\n\n Use `string_date_iso8601` instead\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); }));
|
|
513
413
|
}
|
|
514
414
|
else if (value instanceof Map) {
|
|
515
415
|
throw new UnexpectedError("".concat(name, " is Map"));
|
|
@@ -521,7 +421,7 @@
|
|
|
521
421
|
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
522
422
|
}
|
|
523
423
|
else if (value instanceof Error) {
|
|
524
|
-
throw new UnexpectedError(spaceTrim__default["default"]("\n
|
|
424
|
+
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n `".concat(name, "` is unserialized Error\n\n Use function `serializeError`\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n\n "); }));
|
|
525
425
|
}
|
|
526
426
|
else {
|
|
527
427
|
try {
|
|
@@ -531,7 +431,7 @@
|
|
|
531
431
|
// Note: undefined in object is serializable - it is just omited
|
|
532
432
|
continue;
|
|
533
433
|
}
|
|
534
|
-
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
434
|
+
checkSerializableAsJson({ name: "".concat(name, ".").concat(subName), value: subValue, message: message });
|
|
535
435
|
}
|
|
536
436
|
}
|
|
537
437
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
@@ -548,7 +448,7 @@
|
|
|
548
448
|
if (!(error instanceof Error)) {
|
|
549
449
|
throw error;
|
|
550
450
|
}
|
|
551
|
-
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
451
|
+
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n `".concat(name, "` is not serializable\n\n ").concat(block(error.toString()), "\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); }));
|
|
552
452
|
}
|
|
553
453
|
/*
|
|
554
454
|
TODO: [0] Is there some more elegant way to check circular references?
|
|
@@ -573,35 +473,210 @@
|
|
|
573
473
|
}
|
|
574
474
|
}
|
|
575
475
|
else {
|
|
576
|
-
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
476
|
+
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n `".concat(name, "` is unknown type\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); }));
|
|
577
477
|
}
|
|
578
478
|
}
|
|
579
479
|
/**
|
|
580
|
-
* TODO:
|
|
480
|
+
* TODO: Can be return type more type-safe? like `asserts options.value is JsonValue`
|
|
581
481
|
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
582
482
|
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
583
483
|
*/
|
|
584
484
|
|
|
585
485
|
/**
|
|
586
|
-
* @@@
|
|
587
486
|
* @@@
|
|
588
487
|
*
|
|
589
|
-
*
|
|
488
|
+
* @public exported from `@promptbook/utils`
|
|
489
|
+
*/
|
|
490
|
+
function deepClone(objectValue) {
|
|
491
|
+
return JSON.parse(JSON.stringify(objectValue));
|
|
492
|
+
/*
|
|
493
|
+
!!!!!!!!
|
|
494
|
+
TODO: [🧠] Is there a better implementation?
|
|
495
|
+
> const propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
496
|
+
> for (const propertyName of propertyNames) {
|
|
497
|
+
> const value = (objectValue as really_any)[propertyName];
|
|
498
|
+
> if (value && typeof value === 'object') {
|
|
499
|
+
> deepClone(value);
|
|
500
|
+
> }
|
|
501
|
+
> }
|
|
502
|
+
> return Object.assign({}, objectValue);
|
|
503
|
+
*/
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
507
|
+
*/
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* Utility to export a JSON object from a function
|
|
590
511
|
*
|
|
591
|
-
*
|
|
592
|
-
*
|
|
593
|
-
*
|
|
594
|
-
*
|
|
512
|
+
* 1) Checks if the value is serializable as JSON
|
|
513
|
+
* 2) Makes a deep clone of the object
|
|
514
|
+
* 2) Orders the object properties
|
|
515
|
+
* 2) Deeply freezes the cloned object
|
|
516
|
+
*
|
|
517
|
+
* Note: This function does not mutates the given object
|
|
518
|
+
*
|
|
519
|
+
* @returns The same type of object as the input but read-only and re-ordered
|
|
520
|
+
* @public exported from `@promptbook/utils`
|
|
595
521
|
*/
|
|
596
|
-
function
|
|
597
|
-
|
|
598
|
-
|
|
522
|
+
function exportJson(options) {
|
|
523
|
+
var name = options.name, value = options.value, order = options.order, message = options.message;
|
|
524
|
+
checkSerializableAsJson({ name: name, value: value, message: message });
|
|
525
|
+
var orderedValue =
|
|
526
|
+
// TODO: Fix error "Type instantiation is excessively deep and possibly infinite."
|
|
527
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
528
|
+
// @ts-ignore
|
|
529
|
+
order === undefined
|
|
530
|
+
? deepClone(value)
|
|
531
|
+
: orderJson({
|
|
532
|
+
value: value,
|
|
533
|
+
// <- Note: checkSerializableAsJson asserts that the value is serializable as JSON
|
|
534
|
+
order: order,
|
|
535
|
+
});
|
|
536
|
+
$deepFreeze(orderedValue);
|
|
537
|
+
return orderedValue;
|
|
599
538
|
}
|
|
600
539
|
/**
|
|
601
|
-
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
602
540
|
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
603
541
|
*/
|
|
604
542
|
|
|
543
|
+
/**
|
|
544
|
+
* Nonce which is used for replacing things in strings
|
|
545
|
+
*
|
|
546
|
+
* @private within the repository
|
|
547
|
+
*/
|
|
548
|
+
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
549
|
+
/**
|
|
550
|
+
* @@@
|
|
551
|
+
*
|
|
552
|
+
* @private within the repository
|
|
553
|
+
*/
|
|
554
|
+
var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
|
|
555
|
+
/**
|
|
556
|
+
* @@@
|
|
557
|
+
*
|
|
558
|
+
* @private within the repository
|
|
559
|
+
*/
|
|
560
|
+
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
561
|
+
/**
|
|
562
|
+
* The names of the parameters that are reserved for special purposes
|
|
563
|
+
*
|
|
564
|
+
* @public exported from `@promptbook/core`
|
|
565
|
+
*/
|
|
566
|
+
exportJson({
|
|
567
|
+
name: 'RESERVED_PARAMETER_NAMES',
|
|
568
|
+
message: "The names of the parameters that are reserved for special purposes",
|
|
569
|
+
value: [
|
|
570
|
+
'content',
|
|
571
|
+
'context',
|
|
572
|
+
'knowledge',
|
|
573
|
+
'examples',
|
|
574
|
+
'modelName',
|
|
575
|
+
'currentDate',
|
|
576
|
+
// <- TODO: list here all command names
|
|
577
|
+
// <- TODO: Add more like 'date', 'modelName',...
|
|
578
|
+
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
579
|
+
],
|
|
580
|
+
});
|
|
581
|
+
/**
|
|
582
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
583
|
+
*/
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* This error type indicates that some limit was reached
|
|
587
|
+
*
|
|
588
|
+
* @public exported from `@promptbook/core`
|
|
589
|
+
*/
|
|
590
|
+
var LimitReachedError = /** @class */ (function (_super) {
|
|
591
|
+
__extends(LimitReachedError, _super);
|
|
592
|
+
function LimitReachedError(message) {
|
|
593
|
+
var _this = _super.call(this, message) || this;
|
|
594
|
+
_this.name = 'LimitReachedError';
|
|
595
|
+
Object.setPrototypeOf(_this, LimitReachedError.prototype);
|
|
596
|
+
return _this;
|
|
597
|
+
}
|
|
598
|
+
return LimitReachedError;
|
|
599
|
+
}(Error));
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* Replaces parameters in template with values from parameters object
|
|
603
|
+
*
|
|
604
|
+
* @param template the template with parameters in {curly} braces
|
|
605
|
+
* @param parameters the object with parameters
|
|
606
|
+
* @returns the template with replaced parameters
|
|
607
|
+
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
608
|
+
* @public exported from `@promptbook/utils`
|
|
609
|
+
*/
|
|
610
|
+
function replaceParameters(template, parameters) {
|
|
611
|
+
var e_1, _a;
|
|
612
|
+
try {
|
|
613
|
+
for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
614
|
+
var _d = __read(_c.value, 2), parameterName = _d[0], parameterValue = _d[1];
|
|
615
|
+
if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
|
|
616
|
+
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` has missing value"));
|
|
617
|
+
}
|
|
618
|
+
else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
|
|
619
|
+
// TODO: [🍵]
|
|
620
|
+
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` is restricted to use"));
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
625
|
+
finally {
|
|
626
|
+
try {
|
|
627
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
628
|
+
}
|
|
629
|
+
finally { if (e_1) throw e_1.error; }
|
|
630
|
+
}
|
|
631
|
+
var replacedTemplates = template;
|
|
632
|
+
var match;
|
|
633
|
+
var loopLimit = LOOP_LIMIT;
|
|
634
|
+
var _loop_1 = function () {
|
|
635
|
+
if (loopLimit-- < 0) {
|
|
636
|
+
throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`');
|
|
637
|
+
}
|
|
638
|
+
var precol = match.groups.precol;
|
|
639
|
+
var parameterName = match.groups.parameterName;
|
|
640
|
+
if (parameterName === '') {
|
|
641
|
+
return "continue";
|
|
642
|
+
}
|
|
643
|
+
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
|
|
644
|
+
throw new PipelineExecutionError('Parameter is already opened or not closed');
|
|
645
|
+
}
|
|
646
|
+
if (parameters[parameterName] === undefined) {
|
|
647
|
+
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
|
|
648
|
+
}
|
|
649
|
+
var parameterValue = parameters[parameterName];
|
|
650
|
+
if (parameterValue === undefined) {
|
|
651
|
+
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
|
|
652
|
+
}
|
|
653
|
+
parameterValue = parameterValue.toString();
|
|
654
|
+
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
655
|
+
parameterValue = parameterValue
|
|
656
|
+
.split('\n')
|
|
657
|
+
.map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
|
|
658
|
+
.join('\n');
|
|
659
|
+
}
|
|
660
|
+
replacedTemplates =
|
|
661
|
+
replacedTemplates.substring(0, match.index + precol.length) +
|
|
662
|
+
parameterValue +
|
|
663
|
+
replacedTemplates.substring(match.index + precol.length + parameterName.length + 2);
|
|
664
|
+
};
|
|
665
|
+
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
|
|
666
|
+
.exec(replacedTemplates))) {
|
|
667
|
+
_loop_1();
|
|
668
|
+
}
|
|
669
|
+
// [💫] Check if there are parameters that are not closed properly
|
|
670
|
+
if (/{\w+$/.test(replacedTemplates)) {
|
|
671
|
+
throw new PipelineExecutionError('Parameter is not closed');
|
|
672
|
+
}
|
|
673
|
+
// [💫] Check if there are parameters that are not opened properly
|
|
674
|
+
if (/^\w+}/.test(replacedTemplates)) {
|
|
675
|
+
throw new PipelineExecutionError('Parameter is not opened');
|
|
676
|
+
}
|
|
677
|
+
return replacedTemplates;
|
|
678
|
+
}
|
|
679
|
+
|
|
605
680
|
/**
|
|
606
681
|
* Function `asSerializable` will convert values which are not serializable to serializable values
|
|
607
682
|
* It walks deeply through the object and converts all values
|
|
@@ -681,7 +756,7 @@
|
|
|
681
756
|
return modelVariant === 'CHAT';
|
|
682
757
|
})) === null || _a === void 0 ? void 0 : _a.modelName);
|
|
683
758
|
if (!modelName) {
|
|
684
|
-
throw new PipelineExecutionError(spaceTrim__default["default"]("\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
|
|
759
|
+
throw new PipelineExecutionError(spaceTrim__default["default"]("\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 "));
|
|
685
760
|
}
|
|
686
761
|
return [4 /*yield*/, vercelProvider.chat(modelName, __assign({ user: (userId === null || userId === void 0 ? void 0 : userId.toString()) || undefined }, additionalChatSettings))];
|
|
687
762
|
case 1:
|
|
@@ -744,18 +819,22 @@
|
|
|
744
819
|
}
|
|
745
820
|
complete = $getCurrentDate();
|
|
746
821
|
usage = UNCERTAIN_USAGE;
|
|
747
|
-
return [2 /*return*/,
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
822
|
+
return [2 /*return*/, exportJson({
|
|
823
|
+
name: 'promptResult',
|
|
824
|
+
message: "Result of `createExecutionToolsFromVercelProvider.callChatModel`",
|
|
825
|
+
value: {
|
|
826
|
+
content: rawResponse.text,
|
|
827
|
+
modelName: modelName,
|
|
828
|
+
timing: {
|
|
829
|
+
start: start,
|
|
830
|
+
complete: complete,
|
|
831
|
+
},
|
|
832
|
+
usage: usage,
|
|
833
|
+
rawPromptContent: rawPromptContent,
|
|
834
|
+
rawRequest: rawRequest,
|
|
835
|
+
rawResponse: asSerializable(rawResponse),
|
|
836
|
+
// <- [🗯]
|
|
753
837
|
},
|
|
754
|
-
usage: usage,
|
|
755
|
-
rawPromptContent: rawPromptContent,
|
|
756
|
-
rawRequest: rawRequest,
|
|
757
|
-
rawResponse: asSerializable(rawResponse),
|
|
758
|
-
// <- [🗯]
|
|
759
838
|
})];
|
|
760
839
|
}
|
|
761
840
|
});
|