@promptbook/browser 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 +167 -199
- 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 +167 -199
- 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
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { BOOK_LANGUAGE_VERSION, PROMPTBOOK_ENGINE_VERSION } from '../version';
|
|
2
2
|
import { renderPromptbookMermaid } from '../conversion/prettify/renderPipelineMermaidOptions';
|
|
3
|
-
import {
|
|
4
|
-
import { extractVariables } from '../conversion/utils/extractVariables';
|
|
5
|
-
import { renameParameter } from '../conversion/utils/renameParameter';
|
|
6
|
-
import { titleToName } from '../conversion/utils/titleToName';
|
|
3
|
+
import { extractVariablesFromScript } from '../conversion/utils/extractVariablesFromScript';
|
|
7
4
|
import { deserializeError } from '../errors/utils/deserializeError';
|
|
8
5
|
import { serializeError } from '../errors/utils/serializeError';
|
|
9
6
|
import { forEachAsync } from '../execution/utils/forEachAsync';
|
|
@@ -45,6 +42,7 @@ import { parseKeywords } from '../utils/normalization/parseKeywords';
|
|
|
45
42
|
import { parseKeywordsFromString } from '../utils/normalization/parseKeywordsFromString';
|
|
46
43
|
import { removeDiacritics } from '../utils/normalization/removeDiacritics';
|
|
47
44
|
import { searchKeywords } from '../utils/normalization/searchKeywords';
|
|
45
|
+
import { titleToName } from '../utils/normalization/titleToName';
|
|
48
46
|
import { spaceTrim } from '../utils/organization/spaceTrim';
|
|
49
47
|
import { extractParameterNames } from '../utils/parameters/extractParameterNames';
|
|
50
48
|
import { replaceParameters } from '../utils/parameters/replaceParameters';
|
|
@@ -75,10 +73,7 @@ import { isValidUrl } from '../utils/validators/url/isValidUrl';
|
|
|
75
73
|
import { isValidUuid } from '../utils/validators/uuid/isValidUuid';
|
|
76
74
|
export { BOOK_LANGUAGE_VERSION, PROMPTBOOK_ENGINE_VERSION };
|
|
77
75
|
export { renderPromptbookMermaid };
|
|
78
|
-
export {
|
|
79
|
-
export { extractVariables };
|
|
80
|
-
export { renameParameter };
|
|
81
|
-
export { titleToName };
|
|
76
|
+
export { extractVariablesFromScript };
|
|
82
77
|
export { deserializeError };
|
|
83
78
|
export { serializeError };
|
|
84
79
|
export { forEachAsync };
|
|
@@ -120,6 +115,7 @@ export { parseKeywords };
|
|
|
120
115
|
export { parseKeywordsFromString };
|
|
121
116
|
export { removeDiacritics };
|
|
122
117
|
export { searchKeywords };
|
|
118
|
+
export { titleToName };
|
|
123
119
|
export { spaceTrim };
|
|
124
120
|
export { extractParameterNames };
|
|
125
121
|
export { replaceParameters };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Command } from './Command';
|
|
2
|
+
/**
|
|
3
|
+
* Command is one piece of the book file section which adds some logic to the task or the whole pipeline.
|
|
4
|
+
* It is parsed from the markdown from ul/ol items - one command per one item.
|
|
5
|
+
*
|
|
6
|
+
* This is a type of the command like "KNOWLEDGE" or "PERSONA"
|
|
7
|
+
*/
|
|
8
|
+
export type CommandType = Command['type'];
|
|
9
|
+
/**
|
|
10
|
+
* Command is one piece of the book file section which adds some logic to the task or the whole pipeline.
|
|
11
|
+
* It is parsed from the markdown from ul/ol items - one command per one item.
|
|
12
|
+
*
|
|
13
|
+
* This is a type of the command like "KNOWLEDGE" or "PERSONA"
|
|
14
|
+
*
|
|
15
|
+
export type CommandTypeOrAlias = Command['type'] | Command['aliasNames'] | Command['deprecatedNames'];
|
|
16
|
+
// <- TODO: [🧘] Implement
|
|
17
|
+
*/
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { CsvSettings } from './formats/csv/CsvSettings';
|
|
2
2
|
import type { IntermediateFilesStrategy } from './types/IntermediateFilesStrategy';
|
|
3
|
+
import type { string_email } from './types/typeAliases';
|
|
4
|
+
import type { string_name } from './types/typeAliases';
|
|
3
5
|
import type { string_url_image } from './types/typeAliases';
|
|
4
6
|
/**
|
|
5
7
|
* Warning message for the generated sections and files files
|
|
@@ -15,6 +17,18 @@ export declare const GENERATOR_WARNING = "\u26A0\uFE0F WARNING: This code has be
|
|
|
15
17
|
* @public exported from `@promptbook/core`
|
|
16
18
|
*/
|
|
17
19
|
export declare const NAME = "Promptbook";
|
|
20
|
+
/**
|
|
21
|
+
* Email of the responsible person
|
|
22
|
+
*
|
|
23
|
+
* @public exported from `@promptbook/core`
|
|
24
|
+
*/
|
|
25
|
+
export declare const ADMIN_EMAIL: string_email;
|
|
26
|
+
/**
|
|
27
|
+
* Name of the responsible person for the Promptbook on GitHub
|
|
28
|
+
*
|
|
29
|
+
* @public exported from `@promptbook/core`
|
|
30
|
+
*/
|
|
31
|
+
export declare const ADMIN_GITHUB_NAME: string_name;
|
|
18
32
|
/**
|
|
19
33
|
* Claim for the Promptbook
|
|
20
34
|
*
|
|
@@ -7,7 +7,7 @@ import type { string_parameter_name } from '../../types/typeAliases';
|
|
|
7
7
|
* @param task the task with used parameters
|
|
8
8
|
* @returns the set of parameter names
|
|
9
9
|
* @throws {ParseError} if the script is invalid
|
|
10
|
-
* @public exported from `@promptbook/
|
|
10
|
+
* @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
|
|
11
11
|
*/
|
|
12
12
|
export declare function extractParameterNamesFromTask(task: ReadonlyDeep<Pick<TaskJson, 'title' | 'description' | 'taskType' | 'content' | 'preparedContent' | 'jokerParameterNames' | 'foreach'>>): Set<string_parameter_name>;
|
|
13
13
|
/**
|
package/esm/typings/src/conversion/utils/{extractVariables.d.ts → extractVariablesFromScript.d.ts}
RENAMED
|
@@ -6,9 +6,9 @@ import type { string_javascript_name } from '../../types/typeAliases';
|
|
|
6
6
|
* @param script from which to extract the variables
|
|
7
7
|
* @returns the list of variable names
|
|
8
8
|
* @throws {ParseError} if the script is invalid
|
|
9
|
-
* @public exported from `@promptbook/utils`
|
|
9
|
+
* @public exported from `@promptbook/utils` <- Note: [👖] This is usable elsewhere than in Promptbook, so keeping in utils
|
|
10
10
|
*/
|
|
11
|
-
export declare function
|
|
11
|
+
export declare function extractVariablesFromScript(script: string_javascript): Set<string_javascript_name>;
|
|
12
12
|
/**
|
|
13
13
|
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
14
14
|
*/
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { CommandType } from '../../commands/_common/types/CommandType';
|
|
2
|
+
import type { PipelineString } from '../../pipeline/PipelineString';
|
|
3
|
+
/**
|
|
4
|
+
* Options for `removePipelineCommand`
|
|
5
|
+
*/
|
|
6
|
+
type RemovePipelineCommandOptions = {
|
|
7
|
+
/**
|
|
8
|
+
* The command you want to remove
|
|
9
|
+
*/
|
|
10
|
+
command: CommandType;
|
|
11
|
+
/**
|
|
12
|
+
* Pipeline you want to remove command from
|
|
13
|
+
*/
|
|
14
|
+
pipeline: PipelineString;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Function `removePipelineCommand` will remove one command from pipeline string
|
|
18
|
+
*
|
|
19
|
+
* @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
|
|
20
|
+
*/
|
|
21
|
+
export declare function removePipelineCommand(options: RemovePipelineCommandOptions): PipelineString;
|
|
22
|
+
export {};
|
package/esm/typings/src/conversion/utils/{renameParameter.d.ts → renamePipelineParameter.d.ts}
RENAMED
|
@@ -16,11 +16,11 @@ type RenameParameterOptions = {
|
|
|
16
16
|
readonly newParameterName: string_name;
|
|
17
17
|
};
|
|
18
18
|
/**
|
|
19
|
-
* Function `
|
|
19
|
+
* Function `renamePipelineParameter` will find all usable parameters for given task
|
|
20
20
|
* In other words, it will find all parameters that are not used in the task itseld and all its dependencies
|
|
21
21
|
*
|
|
22
22
|
* @throws {PipelineLogicError} If the new parameter name is already used in the pipeline
|
|
23
|
-
* @public exported from `@promptbook/
|
|
23
|
+
* @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
|
|
24
24
|
*/
|
|
25
|
-
export declare function
|
|
25
|
+
export declare function renamePipelineParameter(options: RenameParameterOptions): PipelineJson;
|
|
26
26
|
export {};
|
|
@@ -24,7 +24,7 @@ export declare const OPENAI_MODELS: ReadonlyArray<AvailableModel & {
|
|
|
24
24
|
* @see https://platform.openai.com/docs/models/gpt-4-turbo-and-gpt-4
|
|
25
25
|
* @see https://openai.com/api/pricing/
|
|
26
26
|
* @see /other/playground/playground.ts
|
|
27
|
-
* TODO: [🍓] Make better
|
|
27
|
+
* TODO: [🍓][💩] Make better
|
|
28
28
|
* TODO: Change model titles to human eg: "gpt-4-turbo-2024-04-09" -> "GPT-4 Turbo (2024-04-09)"
|
|
29
29
|
* TODO: [🚸] Not all models are compatible with JSON mode, add this information here and use it
|
|
30
30
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -8,5 +8,5 @@ export type PipelineString = string & {
|
|
|
8
8
|
readonly _type: 'Promptbook';
|
|
9
9
|
};
|
|
10
10
|
/**
|
|
11
|
-
* TODO:
|
|
11
|
+
* TODO: [💩] Better validation (validatePipelineString) or remove branded type and make it just string
|
|
12
12
|
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/browser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.78.2",
|
|
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/browser.index.d.ts",
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"@promptbook/core": "0.
|
|
57
|
+
"@promptbook/core": "0.78.2"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"spacetrim": "0.11.59"
|
package/umd/index.umd.js
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
*
|
|
21
21
|
* @see https://github.com/webgptorg/promptbook
|
|
22
22
|
*/
|
|
23
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.
|
|
23
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.78.1';
|
|
24
24
|
/**
|
|
25
25
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
26
26
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -212,198 +212,25 @@
|
|
|
212
212
|
var $isRunningInWebWorker = new Function("\n try {\n if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {\n return true;\n } else {\n return false;\n }\n } catch (e) {\n return false;\n }\n");
|
|
213
213
|
|
|
214
214
|
/**
|
|
215
|
-
*
|
|
215
|
+
* Name for the Promptbook
|
|
216
216
|
*
|
|
217
|
-
*
|
|
218
|
-
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
219
|
-
*
|
|
220
|
-
* @returns The same object as the input, but deeply frozen
|
|
221
|
-
* @public exported from `@promptbook/utils`
|
|
222
|
-
*/
|
|
223
|
-
function $deepFreeze(objectValue) {
|
|
224
|
-
var e_1, _a;
|
|
225
|
-
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
226
|
-
try {
|
|
227
|
-
for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
|
|
228
|
-
var propertyName = propertyNames_1_1.value;
|
|
229
|
-
var value = objectValue[propertyName];
|
|
230
|
-
if (value && typeof value === 'object') {
|
|
231
|
-
$deepFreeze(value);
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
236
|
-
finally {
|
|
237
|
-
try {
|
|
238
|
-
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
239
|
-
}
|
|
240
|
-
finally { if (e_1) throw e_1.error; }
|
|
241
|
-
}
|
|
242
|
-
return Object.freeze(objectValue);
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
246
|
-
*/
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
217
|
+
* TODO: [🗽] Unite branding and make single place for it
|
|
250
218
|
*
|
|
251
219
|
* @public exported from `@promptbook/core`
|
|
252
220
|
*/
|
|
253
|
-
var
|
|
254
|
-
__extends(UnexpectedError, _super);
|
|
255
|
-
function UnexpectedError(message) {
|
|
256
|
-
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;
|
|
257
|
-
_this.name = 'UnexpectedError';
|
|
258
|
-
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
259
|
-
return _this;
|
|
260
|
-
}
|
|
261
|
-
return UnexpectedError;
|
|
262
|
-
}(Error));
|
|
263
|
-
|
|
221
|
+
var NAME = "Promptbook";
|
|
264
222
|
/**
|
|
265
|
-
*
|
|
266
|
-
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
267
|
-
*
|
|
268
|
-
* - Almost all primitives are serializable BUT:
|
|
269
|
-
* - `undefined` is not serializable
|
|
270
|
-
* - `NaN` is not serializable
|
|
271
|
-
* - Objects and arrays are serializable if all their properties are serializable
|
|
272
|
-
* - Functions are not serializable
|
|
273
|
-
* - Circular references are not serializable
|
|
274
|
-
* - `Date` objects are not serializable
|
|
275
|
-
* - `Map` and `Set` objects are not serializable
|
|
276
|
-
* - `RegExp` objects are not serializable
|
|
277
|
-
* - `Error` objects are not serializable
|
|
278
|
-
* - `Symbol` objects are not serializable
|
|
279
|
-
* - And much more...
|
|
223
|
+
* Email of the responsible person
|
|
280
224
|
*
|
|
281
|
-
* @
|
|
282
|
-
* @public exported from `@promptbook/utils`
|
|
283
|
-
*/
|
|
284
|
-
function checkSerializableAsJson(name, value) {
|
|
285
|
-
var e_1, _a;
|
|
286
|
-
if (value === undefined) {
|
|
287
|
-
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
288
|
-
}
|
|
289
|
-
else if (value === null) {
|
|
290
|
-
return;
|
|
291
|
-
}
|
|
292
|
-
else if (typeof value === 'boolean') {
|
|
293
|
-
return;
|
|
294
|
-
}
|
|
295
|
-
else if (typeof value === 'number' && !isNaN(value)) {
|
|
296
|
-
return;
|
|
297
|
-
}
|
|
298
|
-
else if (typeof value === 'string') {
|
|
299
|
-
return;
|
|
300
|
-
}
|
|
301
|
-
else if (typeof value === 'symbol') {
|
|
302
|
-
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
303
|
-
}
|
|
304
|
-
else if (typeof value === 'function') {
|
|
305
|
-
throw new UnexpectedError("".concat(name, " is function"));
|
|
306
|
-
}
|
|
307
|
-
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
308
|
-
for (var i = 0; i < value.length; i++) {
|
|
309
|
-
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
else if (typeof value === 'object') {
|
|
313
|
-
if (value instanceof Date) {
|
|
314
|
-
throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
315
|
-
}
|
|
316
|
-
else if (value instanceof Map) {
|
|
317
|
-
throw new UnexpectedError("".concat(name, " is Map"));
|
|
318
|
-
}
|
|
319
|
-
else if (value instanceof Set) {
|
|
320
|
-
throw new UnexpectedError("".concat(name, " is Set"));
|
|
321
|
-
}
|
|
322
|
-
else if (value instanceof RegExp) {
|
|
323
|
-
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
324
|
-
}
|
|
325
|
-
else if (value instanceof Error) {
|
|
326
|
-
throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
327
|
-
}
|
|
328
|
-
else {
|
|
329
|
-
try {
|
|
330
|
-
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
331
|
-
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
332
|
-
if (subValue === undefined) {
|
|
333
|
-
// Note: undefined in object is serializable - it is just omited
|
|
334
|
-
continue;
|
|
335
|
-
}
|
|
336
|
-
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
340
|
-
finally {
|
|
341
|
-
try {
|
|
342
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
343
|
-
}
|
|
344
|
-
finally { if (e_1) throw e_1.error; }
|
|
345
|
-
}
|
|
346
|
-
try {
|
|
347
|
-
JSON.stringify(value); // <- TODO: [0]
|
|
348
|
-
}
|
|
349
|
-
catch (error) {
|
|
350
|
-
if (!(error instanceof Error)) {
|
|
351
|
-
throw error;
|
|
352
|
-
}
|
|
353
|
-
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
354
|
-
}
|
|
355
|
-
/*
|
|
356
|
-
TODO: [0] Is there some more elegant way to check circular references?
|
|
357
|
-
const seen = new Set();
|
|
358
|
-
const stack = [{ value }];
|
|
359
|
-
while (stack.length > 0) {
|
|
360
|
-
const { value } = stack.pop()!;
|
|
361
|
-
if (typeof value === 'object' && value !== null) {
|
|
362
|
-
if (seen.has(value)) {
|
|
363
|
-
throw new UnexpectedError(`${name} has circular reference`);
|
|
364
|
-
}
|
|
365
|
-
seen.add(value);
|
|
366
|
-
if (Array.isArray(value)) {
|
|
367
|
-
stack.push(...value.map((value) => ({ value })));
|
|
368
|
-
} else {
|
|
369
|
-
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
*/
|
|
374
|
-
return;
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
else {
|
|
378
|
-
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
/**
|
|
382
|
-
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
383
|
-
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
384
|
-
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
225
|
+
* @public exported from `@promptbook/core`
|
|
385
226
|
*/
|
|
386
|
-
|
|
227
|
+
var ADMIN_EMAIL = 'me@pavolhejny.com';
|
|
387
228
|
/**
|
|
388
|
-
*
|
|
389
|
-
* @@@
|
|
390
|
-
*
|
|
391
|
-
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
229
|
+
* Name of the responsible person for the Promptbook on GitHub
|
|
392
230
|
*
|
|
393
|
-
* @
|
|
394
|
-
* @param objectValue - Object to be deeply frozen
|
|
395
|
-
* @returns The same object as the input, but deeply frozen
|
|
396
|
-
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
397
|
-
*/
|
|
398
|
-
function $asDeeplyFrozenSerializableJson(name, objectValue) {
|
|
399
|
-
checkSerializableAsJson(name, objectValue);
|
|
400
|
-
return $deepFreeze(objectValue);
|
|
401
|
-
}
|
|
402
|
-
/**
|
|
403
|
-
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
404
|
-
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
231
|
+
* @public exported from `@promptbook/core`
|
|
405
232
|
*/
|
|
406
|
-
|
|
233
|
+
var ADMIN_GITHUB_NAME = 'hejny';
|
|
407
234
|
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
408
235
|
/**
|
|
409
236
|
* The maximum number of iterations for a loops
|
|
@@ -417,22 +244,6 @@
|
|
|
417
244
|
* @private within the repository
|
|
418
245
|
*/
|
|
419
246
|
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
420
|
-
/**
|
|
421
|
-
* The names of the parameters that are reserved for special purposes
|
|
422
|
-
*
|
|
423
|
-
* @public exported from `@promptbook/core`
|
|
424
|
-
*/
|
|
425
|
-
$asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', [
|
|
426
|
-
'content',
|
|
427
|
-
'context',
|
|
428
|
-
'knowledge',
|
|
429
|
-
'examples',
|
|
430
|
-
'modelName',
|
|
431
|
-
'currentDate',
|
|
432
|
-
// <- TODO: list here all command names
|
|
433
|
-
// <- TODO: Add more like 'date', 'modelName',...
|
|
434
|
-
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
435
|
-
]);
|
|
436
247
|
// <- TODO: [🧜♂️]
|
|
437
248
|
/**
|
|
438
249
|
* @@@
|
|
@@ -467,6 +278,40 @@
|
|
|
467
278
|
return NotYetImplementedError;
|
|
468
279
|
}(Error));
|
|
469
280
|
|
|
281
|
+
/**
|
|
282
|
+
* Make error report URL for the given error
|
|
283
|
+
*
|
|
284
|
+
* @private !!!!!!
|
|
285
|
+
*/
|
|
286
|
+
function getErrorReportUrl(error) {
|
|
287
|
+
var report = {
|
|
288
|
+
title: "\uD83D\uDC1C Error report from ".concat(NAME),
|
|
289
|
+
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 "); }),
|
|
290
|
+
};
|
|
291
|
+
var reportUrl = new URL("https://github.com/webgptorg/promptbook/issues/new");
|
|
292
|
+
reportUrl.searchParams.set('labels', 'bug');
|
|
293
|
+
reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
|
|
294
|
+
reportUrl.searchParams.set('title', report.title);
|
|
295
|
+
reportUrl.searchParams.set('body', report.body);
|
|
296
|
+
return reportUrl;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
301
|
+
*
|
|
302
|
+
* @public exported from `@promptbook/core`
|
|
303
|
+
*/
|
|
304
|
+
var UnexpectedError = /** @class */ (function (_super) {
|
|
305
|
+
__extends(UnexpectedError, _super);
|
|
306
|
+
function UnexpectedError(message) {
|
|
307
|
+
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;
|
|
308
|
+
_this.name = 'UnexpectedError';
|
|
309
|
+
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
310
|
+
return _this;
|
|
311
|
+
}
|
|
312
|
+
return UnexpectedError;
|
|
313
|
+
}(Error));
|
|
314
|
+
|
|
470
315
|
/**
|
|
471
316
|
* @@@
|
|
472
317
|
*
|
|
@@ -674,6 +519,129 @@
|
|
|
674
519
|
});
|
|
675
520
|
}
|
|
676
521
|
|
|
522
|
+
/**
|
|
523
|
+
* Checks if the value is [🚉] serializable as JSON
|
|
524
|
+
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
525
|
+
*
|
|
526
|
+
* - Almost all primitives are serializable BUT:
|
|
527
|
+
* - `undefined` is not serializable
|
|
528
|
+
* - `NaN` is not serializable
|
|
529
|
+
* - Objects and arrays are serializable if all their properties are serializable
|
|
530
|
+
* - Functions are not serializable
|
|
531
|
+
* - Circular references are not serializable
|
|
532
|
+
* - `Date` objects are not serializable
|
|
533
|
+
* - `Map` and `Set` objects are not serializable
|
|
534
|
+
* - `RegExp` objects are not serializable
|
|
535
|
+
* - `Error` objects are not serializable
|
|
536
|
+
* - `Symbol` objects are not serializable
|
|
537
|
+
* - And much more...
|
|
538
|
+
*
|
|
539
|
+
* @throws UnexpectedError if the value is not serializable as JSON
|
|
540
|
+
* @public exported from `@promptbook/utils`
|
|
541
|
+
*/
|
|
542
|
+
function checkSerializableAsJson(name, value) {
|
|
543
|
+
var e_1, _a;
|
|
544
|
+
if (value === undefined) {
|
|
545
|
+
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
546
|
+
}
|
|
547
|
+
else if (value === null) {
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
else if (typeof value === 'boolean') {
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
553
|
+
else if (typeof value === 'number' && !isNaN(value)) {
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
556
|
+
else if (typeof value === 'string') {
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
559
|
+
else if (typeof value === 'symbol') {
|
|
560
|
+
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
561
|
+
}
|
|
562
|
+
else if (typeof value === 'function') {
|
|
563
|
+
throw new UnexpectedError("".concat(name, " is function"));
|
|
564
|
+
}
|
|
565
|
+
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
566
|
+
for (var i = 0; i < value.length; i++) {
|
|
567
|
+
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
else if (typeof value === 'object') {
|
|
571
|
+
if (value instanceof Date) {
|
|
572
|
+
throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
573
|
+
}
|
|
574
|
+
else if (value instanceof Map) {
|
|
575
|
+
throw new UnexpectedError("".concat(name, " is Map"));
|
|
576
|
+
}
|
|
577
|
+
else if (value instanceof Set) {
|
|
578
|
+
throw new UnexpectedError("".concat(name, " is Set"));
|
|
579
|
+
}
|
|
580
|
+
else if (value instanceof RegExp) {
|
|
581
|
+
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
582
|
+
}
|
|
583
|
+
else if (value instanceof Error) {
|
|
584
|
+
throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
585
|
+
}
|
|
586
|
+
else {
|
|
587
|
+
try {
|
|
588
|
+
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
589
|
+
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
590
|
+
if (subValue === undefined) {
|
|
591
|
+
// Note: undefined in object is serializable - it is just omited
|
|
592
|
+
continue;
|
|
593
|
+
}
|
|
594
|
+
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
598
|
+
finally {
|
|
599
|
+
try {
|
|
600
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
601
|
+
}
|
|
602
|
+
finally { if (e_1) throw e_1.error; }
|
|
603
|
+
}
|
|
604
|
+
try {
|
|
605
|
+
JSON.stringify(value); // <- TODO: [0]
|
|
606
|
+
}
|
|
607
|
+
catch (error) {
|
|
608
|
+
if (!(error instanceof Error)) {
|
|
609
|
+
throw error;
|
|
610
|
+
}
|
|
611
|
+
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
612
|
+
}
|
|
613
|
+
/*
|
|
614
|
+
TODO: [0] Is there some more elegant way to check circular references?
|
|
615
|
+
const seen = new Set();
|
|
616
|
+
const stack = [{ value }];
|
|
617
|
+
while (stack.length > 0) {
|
|
618
|
+
const { value } = stack.pop()!;
|
|
619
|
+
if (typeof value === 'object' && value !== null) {
|
|
620
|
+
if (seen.has(value)) {
|
|
621
|
+
throw new UnexpectedError(`${name} has circular reference`);
|
|
622
|
+
}
|
|
623
|
+
seen.add(value);
|
|
624
|
+
if (Array.isArray(value)) {
|
|
625
|
+
stack.push(...value.map((value) => ({ value })));
|
|
626
|
+
} else {
|
|
627
|
+
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
*/
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
else {
|
|
636
|
+
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
/**
|
|
640
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
641
|
+
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
642
|
+
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
643
|
+
*/
|
|
644
|
+
|
|
677
645
|
/**
|
|
678
646
|
* Tests if the value is [🚉] serializable as JSON
|
|
679
647
|
*
|