@promptbook/vercel 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 +183 -161
- 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 +178 -156
- 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/vercel",
|
|
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/vercel.index.d.ts",
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"@promptbook/core": "0.
|
|
57
|
+
"@promptbook/core": "0.78.2"
|
|
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.78.1';
|
|
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
|
|
@@ -264,6 +264,103 @@
|
|
|
264
264
|
return new Date().toISOString();
|
|
265
265
|
}
|
|
266
266
|
|
|
267
|
+
/**
|
|
268
|
+
* Name for the Promptbook
|
|
269
|
+
*
|
|
270
|
+
* TODO: [🗽] Unite branding and make single place for it
|
|
271
|
+
*
|
|
272
|
+
* @public exported from `@promptbook/core`
|
|
273
|
+
*/
|
|
274
|
+
var NAME = "Promptbook";
|
|
275
|
+
/**
|
|
276
|
+
* Email of the responsible person
|
|
277
|
+
*
|
|
278
|
+
* @public exported from `@promptbook/core`
|
|
279
|
+
*/
|
|
280
|
+
var ADMIN_EMAIL = 'me@pavolhejny.com';
|
|
281
|
+
/**
|
|
282
|
+
* Name of the responsible person for the Promptbook on GitHub
|
|
283
|
+
*
|
|
284
|
+
* @public exported from `@promptbook/core`
|
|
285
|
+
*/
|
|
286
|
+
var ADMIN_GITHUB_NAME = 'hejny';
|
|
287
|
+
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
288
|
+
/**
|
|
289
|
+
* The maximum number of iterations for a loops
|
|
290
|
+
*
|
|
291
|
+
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
292
|
+
*/
|
|
293
|
+
var LOOP_LIMIT = 1000;
|
|
294
|
+
/**
|
|
295
|
+
* Nonce which is used for replacing things in strings
|
|
296
|
+
*
|
|
297
|
+
* @private within the repository
|
|
298
|
+
*/
|
|
299
|
+
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
300
|
+
/**
|
|
301
|
+
* @@@
|
|
302
|
+
*
|
|
303
|
+
* @private within the repository
|
|
304
|
+
*/
|
|
305
|
+
var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
|
|
306
|
+
/**
|
|
307
|
+
* @@@
|
|
308
|
+
*
|
|
309
|
+
* @private within the repository
|
|
310
|
+
*/
|
|
311
|
+
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
312
|
+
// <- TODO: [🧜♂️]
|
|
313
|
+
/**
|
|
314
|
+
* @@@
|
|
315
|
+
*
|
|
316
|
+
* @public exported from `@promptbook/core`
|
|
317
|
+
*/
|
|
318
|
+
Object.freeze({
|
|
319
|
+
delimiter: ',',
|
|
320
|
+
quoteChar: '"',
|
|
321
|
+
newline: '\n',
|
|
322
|
+
skipEmptyLines: true,
|
|
323
|
+
});
|
|
324
|
+
/**
|
|
325
|
+
* TODO: Extract `constants.ts` from `config.ts`
|
|
326
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
327
|
+
* TODO: [🧠][🧜♂️] Maybe join remoteUrl and path into single value
|
|
328
|
+
*/
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* This error type indicates that some limit was reached
|
|
332
|
+
*
|
|
333
|
+
* @public exported from `@promptbook/core`
|
|
334
|
+
*/
|
|
335
|
+
var LimitReachedError = /** @class */ (function (_super) {
|
|
336
|
+
__extends(LimitReachedError, _super);
|
|
337
|
+
function LimitReachedError(message) {
|
|
338
|
+
var _this = _super.call(this, message) || this;
|
|
339
|
+
_this.name = 'LimitReachedError';
|
|
340
|
+
Object.setPrototypeOf(_this, LimitReachedError.prototype);
|
|
341
|
+
return _this;
|
|
342
|
+
}
|
|
343
|
+
return LimitReachedError;
|
|
344
|
+
}(Error));
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Make error report URL for the given error
|
|
348
|
+
*
|
|
349
|
+
* @private !!!!!!
|
|
350
|
+
*/
|
|
351
|
+
function getErrorReportUrl(error) {
|
|
352
|
+
var report = {
|
|
353
|
+
title: "\uD83D\uDC1C Error report from ".concat(NAME),
|
|
354
|
+
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 "); }),
|
|
355
|
+
};
|
|
356
|
+
var reportUrl = new URL("https://github.com/webgptorg/promptbook/issues/new");
|
|
357
|
+
reportUrl.searchParams.set('labels', 'bug');
|
|
358
|
+
reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
|
|
359
|
+
reportUrl.searchParams.set('title', report.title);
|
|
360
|
+
reportUrl.searchParams.set('body', report.body);
|
|
361
|
+
return reportUrl;
|
|
362
|
+
}
|
|
363
|
+
|
|
267
364
|
/**
|
|
268
365
|
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
269
366
|
*
|
|
@@ -272,7 +369,7 @@
|
|
|
272
369
|
var UnexpectedError = /** @class */ (function (_super) {
|
|
273
370
|
__extends(UnexpectedError, _super);
|
|
274
371
|
function UnexpectedError(message) {
|
|
275
|
-
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
|
|
372
|
+
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;
|
|
276
373
|
_this.name = 'UnexpectedError';
|
|
277
374
|
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
278
375
|
return _this;
|
|
@@ -280,6 +377,85 @@
|
|
|
280
377
|
return UnexpectedError;
|
|
281
378
|
}(Error));
|
|
282
379
|
|
|
380
|
+
/**
|
|
381
|
+
* Replaces parameters in template with values from parameters object
|
|
382
|
+
*
|
|
383
|
+
* @param template the template with parameters in {curly} braces
|
|
384
|
+
* @param parameters the object with parameters
|
|
385
|
+
* @returns the template with replaced parameters
|
|
386
|
+
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
387
|
+
* @public exported from `@promptbook/utils`
|
|
388
|
+
*/
|
|
389
|
+
function replaceParameters(template, parameters) {
|
|
390
|
+
var e_1, _a;
|
|
391
|
+
try {
|
|
392
|
+
for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
393
|
+
var _d = __read(_c.value, 2), parameterName = _d[0], parameterValue = _d[1];
|
|
394
|
+
if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
|
|
395
|
+
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` has missing value"));
|
|
396
|
+
}
|
|
397
|
+
else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
|
|
398
|
+
// TODO: [🍵]
|
|
399
|
+
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` is restricted to use"));
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
404
|
+
finally {
|
|
405
|
+
try {
|
|
406
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
407
|
+
}
|
|
408
|
+
finally { if (e_1) throw e_1.error; }
|
|
409
|
+
}
|
|
410
|
+
var replacedTemplates = template;
|
|
411
|
+
var match;
|
|
412
|
+
var loopLimit = LOOP_LIMIT;
|
|
413
|
+
var _loop_1 = function () {
|
|
414
|
+
if (loopLimit-- < 0) {
|
|
415
|
+
throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`');
|
|
416
|
+
}
|
|
417
|
+
var precol = match.groups.precol;
|
|
418
|
+
var parameterName = match.groups.parameterName;
|
|
419
|
+
if (parameterName === '') {
|
|
420
|
+
return "continue";
|
|
421
|
+
}
|
|
422
|
+
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
|
|
423
|
+
throw new PipelineExecutionError('Parameter is already opened or not closed');
|
|
424
|
+
}
|
|
425
|
+
if (parameters[parameterName] === undefined) {
|
|
426
|
+
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
|
|
427
|
+
}
|
|
428
|
+
var parameterValue = parameters[parameterName];
|
|
429
|
+
if (parameterValue === undefined) {
|
|
430
|
+
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
|
|
431
|
+
}
|
|
432
|
+
parameterValue = parameterValue.toString();
|
|
433
|
+
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
434
|
+
parameterValue = parameterValue
|
|
435
|
+
.split('\n')
|
|
436
|
+
.map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
|
|
437
|
+
.join('\n');
|
|
438
|
+
}
|
|
439
|
+
replacedTemplates =
|
|
440
|
+
replacedTemplates.substring(0, match.index + precol.length) +
|
|
441
|
+
parameterValue +
|
|
442
|
+
replacedTemplates.substring(match.index + precol.length + parameterName.length + 2);
|
|
443
|
+
};
|
|
444
|
+
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
|
|
445
|
+
.exec(replacedTemplates))) {
|
|
446
|
+
_loop_1();
|
|
447
|
+
}
|
|
448
|
+
// [💫] Check if there are parameters that are not closed properly
|
|
449
|
+
if (/{\w+$/.test(replacedTemplates)) {
|
|
450
|
+
throw new PipelineExecutionError('Parameter is not closed');
|
|
451
|
+
}
|
|
452
|
+
// [💫] Check if there are parameters that are not opened properly
|
|
453
|
+
if (/^\w+}/.test(replacedTemplates)) {
|
|
454
|
+
throw new PipelineExecutionError('Parameter is not opened');
|
|
455
|
+
}
|
|
456
|
+
return replacedTemplates;
|
|
457
|
+
}
|
|
458
|
+
|
|
283
459
|
/**
|
|
284
460
|
* Checks if the value is [🚉] serializable as JSON
|
|
285
461
|
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
@@ -423,160 +599,6 @@
|
|
|
423
599
|
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
424
600
|
*/
|
|
425
601
|
|
|
426
|
-
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
427
|
-
/**
|
|
428
|
-
* The maximum number of iterations for a loops
|
|
429
|
-
*
|
|
430
|
-
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
431
|
-
*/
|
|
432
|
-
var LOOP_LIMIT = 1000;
|
|
433
|
-
/**
|
|
434
|
-
* Nonce which is used for replacing things in strings
|
|
435
|
-
*
|
|
436
|
-
* @private within the repository
|
|
437
|
-
*/
|
|
438
|
-
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
439
|
-
/**
|
|
440
|
-
* The names of the parameters that are reserved for special purposes
|
|
441
|
-
*
|
|
442
|
-
* @public exported from `@promptbook/core`
|
|
443
|
-
*/
|
|
444
|
-
$asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', [
|
|
445
|
-
'content',
|
|
446
|
-
'context',
|
|
447
|
-
'knowledge',
|
|
448
|
-
'examples',
|
|
449
|
-
'modelName',
|
|
450
|
-
'currentDate',
|
|
451
|
-
// <- TODO: list here all command names
|
|
452
|
-
// <- TODO: Add more like 'date', 'modelName',...
|
|
453
|
-
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
454
|
-
]);
|
|
455
|
-
/**
|
|
456
|
-
* @@@
|
|
457
|
-
*
|
|
458
|
-
* @private within the repository
|
|
459
|
-
*/
|
|
460
|
-
var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
|
|
461
|
-
/**
|
|
462
|
-
* @@@
|
|
463
|
-
*
|
|
464
|
-
* @private within the repository
|
|
465
|
-
*/
|
|
466
|
-
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
467
|
-
// <- TODO: [🧜♂️]
|
|
468
|
-
/**
|
|
469
|
-
* @@@
|
|
470
|
-
*
|
|
471
|
-
* @public exported from `@promptbook/core`
|
|
472
|
-
*/
|
|
473
|
-
Object.freeze({
|
|
474
|
-
delimiter: ',',
|
|
475
|
-
quoteChar: '"',
|
|
476
|
-
newline: '\n',
|
|
477
|
-
skipEmptyLines: true,
|
|
478
|
-
});
|
|
479
|
-
/**
|
|
480
|
-
* TODO: Extract `constants.ts` from `config.ts`
|
|
481
|
-
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
482
|
-
* TODO: [🧠][🧜♂️] Maybe join remoteUrl and path into single value
|
|
483
|
-
*/
|
|
484
|
-
|
|
485
|
-
/**
|
|
486
|
-
* This error type indicates that some limit was reached
|
|
487
|
-
*
|
|
488
|
-
* @public exported from `@promptbook/core`
|
|
489
|
-
*/
|
|
490
|
-
var LimitReachedError = /** @class */ (function (_super) {
|
|
491
|
-
__extends(LimitReachedError, _super);
|
|
492
|
-
function LimitReachedError(message) {
|
|
493
|
-
var _this = _super.call(this, message) || this;
|
|
494
|
-
_this.name = 'LimitReachedError';
|
|
495
|
-
Object.setPrototypeOf(_this, LimitReachedError.prototype);
|
|
496
|
-
return _this;
|
|
497
|
-
}
|
|
498
|
-
return LimitReachedError;
|
|
499
|
-
}(Error));
|
|
500
|
-
|
|
501
|
-
/**
|
|
502
|
-
* Replaces parameters in template with values from parameters object
|
|
503
|
-
*
|
|
504
|
-
* @param template the template with parameters in {curly} braces
|
|
505
|
-
* @param parameters the object with parameters
|
|
506
|
-
* @returns the template with replaced parameters
|
|
507
|
-
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
508
|
-
* @public exported from `@promptbook/utils`
|
|
509
|
-
*/
|
|
510
|
-
function replaceParameters(template, parameters) {
|
|
511
|
-
var e_1, _a;
|
|
512
|
-
try {
|
|
513
|
-
for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
514
|
-
var _d = __read(_c.value, 2), parameterName = _d[0], parameterValue = _d[1];
|
|
515
|
-
if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
|
|
516
|
-
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` has missing value"));
|
|
517
|
-
}
|
|
518
|
-
else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
|
|
519
|
-
// TODO: [🍵]
|
|
520
|
-
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` is restricted to use"));
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
525
|
-
finally {
|
|
526
|
-
try {
|
|
527
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
528
|
-
}
|
|
529
|
-
finally { if (e_1) throw e_1.error; }
|
|
530
|
-
}
|
|
531
|
-
var replacedTemplates = template;
|
|
532
|
-
var match;
|
|
533
|
-
var loopLimit = LOOP_LIMIT;
|
|
534
|
-
var _loop_1 = function () {
|
|
535
|
-
if (loopLimit-- < 0) {
|
|
536
|
-
throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`');
|
|
537
|
-
}
|
|
538
|
-
var precol = match.groups.precol;
|
|
539
|
-
var parameterName = match.groups.parameterName;
|
|
540
|
-
if (parameterName === '') {
|
|
541
|
-
return "continue";
|
|
542
|
-
}
|
|
543
|
-
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
|
|
544
|
-
throw new PipelineExecutionError('Parameter is already opened or not closed');
|
|
545
|
-
}
|
|
546
|
-
if (parameters[parameterName] === undefined) {
|
|
547
|
-
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
|
|
548
|
-
}
|
|
549
|
-
var parameterValue = parameters[parameterName];
|
|
550
|
-
if (parameterValue === undefined) {
|
|
551
|
-
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
|
|
552
|
-
}
|
|
553
|
-
parameterValue = parameterValue.toString();
|
|
554
|
-
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
555
|
-
parameterValue = parameterValue
|
|
556
|
-
.split('\n')
|
|
557
|
-
.map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
|
|
558
|
-
.join('\n');
|
|
559
|
-
}
|
|
560
|
-
replacedTemplates =
|
|
561
|
-
replacedTemplates.substring(0, match.index + precol.length) +
|
|
562
|
-
parameterValue +
|
|
563
|
-
replacedTemplates.substring(match.index + precol.length + parameterName.length + 2);
|
|
564
|
-
};
|
|
565
|
-
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
|
|
566
|
-
.exec(replacedTemplates))) {
|
|
567
|
-
_loop_1();
|
|
568
|
-
}
|
|
569
|
-
// [💫] Check if there are parameters that are not closed properly
|
|
570
|
-
if (/{\w+$/.test(replacedTemplates)) {
|
|
571
|
-
throw new PipelineExecutionError('Parameter is not closed');
|
|
572
|
-
}
|
|
573
|
-
// [💫] Check if there are parameters that are not opened properly
|
|
574
|
-
if (/^\w+}/.test(replacedTemplates)) {
|
|
575
|
-
throw new PipelineExecutionError('Parameter is not opened');
|
|
576
|
-
}
|
|
577
|
-
return replacedTemplates;
|
|
578
|
-
}
|
|
579
|
-
|
|
580
602
|
/**
|
|
581
603
|
* Function `asSerializable` will convert values which are not serializable to serializable values
|
|
582
604
|
* It walks deeply through the object and converts all values
|