@promptbook/node 0.77.0 → 0.78.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 +113 -53
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +8 -2
- 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/cli/test/ptbk.d.ts +1 -1
- package/esm/typings/src/commands/_common/types/CommandType.d.ts +17 -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/0-index.d.ts +46 -1
- package/esm/typings/src/errors/utils/ErrorJson.d.ts +2 -2
- package/esm/typings/src/llm-providers/_common/register/createLlmToolsFromConfiguration.test.d.ts +1 -0
- package/esm/typings/src/utils/normalization/titleToName.test.d.ts +1 -0
- package/package.json +2 -2
- package/umd/index.umd.js +113 -53
- 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
|
@@ -30,12 +30,15 @@ import { pipelineJsonToString } from '../conversion/pipelineJsonToString';
|
|
|
30
30
|
import { pipelineStringToJson } from '../conversion/pipelineStringToJson';
|
|
31
31
|
import { pipelineStringToJsonSync } from '../conversion/pipelineStringToJsonSync';
|
|
32
32
|
import { prettifyPipelineString } from '../conversion/prettify/prettifyPipelineString';
|
|
33
|
+
import { extractParameterNamesFromTask } from '../conversion/utils/extractParameterNamesFromTask';
|
|
34
|
+
import { removePipelineCommand } from '../conversion/utils/removePipelineCommand';
|
|
35
|
+
import { renamePipelineParameter } from '../conversion/utils/renamePipelineParameter';
|
|
33
36
|
import { stringifyPipelineJson } from '../conversion/utils/stringifyPipelineJson';
|
|
34
37
|
import { validatePipeline } from '../conversion/validation/validatePipeline';
|
|
35
38
|
import { CallbackInterfaceTools } from '../dialogs/callback/CallbackInterfaceTools';
|
|
36
39
|
import type { CallbackInterfaceToolsOptions } from '../dialogs/callback/CallbackInterfaceToolsOptions';
|
|
37
40
|
import { BoilerplateError } from '../errors/0-BoilerplateError';
|
|
38
|
-
import {
|
|
41
|
+
import { PROMPTBOOK_ERRORS } from '../errors/0-index';
|
|
39
42
|
import { AbstractFormatError } from '../errors/AbstractFormatError';
|
|
40
43
|
import { CollectionError } from '../errors/CollectionError';
|
|
41
44
|
import { EnvironmentMismatchError } from '../errors/EnvironmentMismatchError';
|
|
@@ -145,12 +148,15 @@ export { pipelineJsonToString };
|
|
|
145
148
|
export { pipelineStringToJson };
|
|
146
149
|
export { pipelineStringToJsonSync };
|
|
147
150
|
export { prettifyPipelineString };
|
|
151
|
+
export { extractParameterNamesFromTask };
|
|
152
|
+
export { removePipelineCommand };
|
|
153
|
+
export { renamePipelineParameter };
|
|
148
154
|
export { stringifyPipelineJson };
|
|
149
155
|
export { validatePipeline };
|
|
150
156
|
export { CallbackInterfaceTools };
|
|
151
157
|
export type { CallbackInterfaceToolsOptions };
|
|
152
158
|
export { BoilerplateError };
|
|
153
|
-
export {
|
|
159
|
+
export { PROMPTBOOK_ERRORS };
|
|
154
160
|
export { AbstractFormatError };
|
|
155
161
|
export { CollectionError };
|
|
156
162
|
export { EnvironmentMismatchError };
|
|
@@ -5,6 +5,8 @@ import type { PipelineBothCommandParser } from '../commands/_common/types/Comman
|
|
|
5
5
|
import type { PipelineHeadCommandParser } from '../commands/_common/types/CommandParser';
|
|
6
6
|
import type { PipelineTaskCommandParser } from '../commands/_common/types/CommandParser';
|
|
7
7
|
import type { CommandParserInput } from '../commands/_common/types/CommandParser';
|
|
8
|
+
import type { CommandType } from '../commands/_common/types/CommandType';
|
|
9
|
+
import type { CommandTypeOrAlias } from '../commands/_common/types/CommandType';
|
|
8
10
|
import type { CommandUsagePlace } from '../commands/_common/types/CommandUsagePlaces';
|
|
9
11
|
import type { ExpectCommand } from '../commands/EXPECT/ExpectCommand';
|
|
10
12
|
import type { ForeachJson } from '../commands/FOREACH/ForeachJson';
|
|
@@ -263,6 +265,8 @@ export type { PipelineBothCommandParser };
|
|
|
263
265
|
export type { PipelineHeadCommandParser };
|
|
264
266
|
export type { PipelineTaskCommandParser };
|
|
265
267
|
export type { CommandParserInput };
|
|
268
|
+
export type { CommandType };
|
|
269
|
+
export type { CommandTypeOrAlias };
|
|
266
270
|
export type { CommandUsagePlace };
|
|
267
271
|
export type { ExpectCommand };
|
|
268
272
|
export type { ForeachJson };
|
|
@@ -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
|
+
*/
|
|
@@ -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 {};
|
|
@@ -18,7 +18,52 @@ import { UnexpectedError } from './UnexpectedError';
|
|
|
18
18
|
*
|
|
19
19
|
* @public exported from `@promptbook/core`
|
|
20
20
|
*/
|
|
21
|
-
export declare const
|
|
21
|
+
export declare const PROMPTBOOK_ERRORS: {
|
|
22
|
+
readonly AbstractFormatError: typeof AbstractFormatError;
|
|
23
|
+
readonly CsvFormatError: typeof CsvFormatError;
|
|
24
|
+
readonly CollectionError: typeof CollectionError;
|
|
25
|
+
readonly EnvironmentMismatchError: typeof EnvironmentMismatchError;
|
|
26
|
+
readonly ExpectError: typeof ExpectError;
|
|
27
|
+
readonly KnowledgeScrapeError: typeof KnowledgeScrapeError;
|
|
28
|
+
readonly LimitReachedError: typeof LimitReachedError;
|
|
29
|
+
readonly MissingToolsError: typeof MissingToolsError;
|
|
30
|
+
readonly NotFoundError: typeof NotFoundError;
|
|
31
|
+
readonly NotYetImplementedError: typeof NotYetImplementedError;
|
|
32
|
+
readonly ParseError: typeof ParseError;
|
|
33
|
+
readonly PipelineExecutionError: typeof PipelineExecutionError;
|
|
34
|
+
readonly PipelineLogicError: typeof PipelineLogicError;
|
|
35
|
+
readonly PipelineUrlError: typeof PipelineUrlError;
|
|
36
|
+
readonly UnexpectedError: typeof UnexpectedError;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Index of all javascript errors
|
|
40
|
+
*
|
|
41
|
+
* @private for internal usage
|
|
42
|
+
*/
|
|
43
|
+
export declare const COMMON_JAVASCRIPT_ERRORS: {
|
|
44
|
+
readonly Error: ErrorConstructor;
|
|
45
|
+
readonly EvalError: EvalErrorConstructor;
|
|
46
|
+
readonly RangeError: RangeErrorConstructor;
|
|
47
|
+
readonly ReferenceError: ReferenceErrorConstructor;
|
|
48
|
+
readonly SyntaxError: SyntaxErrorConstructor;
|
|
49
|
+
readonly TypeError: TypeErrorConstructor;
|
|
50
|
+
readonly URIError: URIErrorConstructor;
|
|
51
|
+
readonly AggregateError: AggregateErrorConstructor;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Index of all errors
|
|
55
|
+
*
|
|
56
|
+
* @private for internal usage
|
|
57
|
+
*/
|
|
58
|
+
export declare const ALL_ERRORS: {
|
|
59
|
+
readonly Error: ErrorConstructor;
|
|
60
|
+
readonly EvalError: EvalErrorConstructor;
|
|
61
|
+
readonly RangeError: RangeErrorConstructor;
|
|
62
|
+
readonly ReferenceError: ReferenceErrorConstructor;
|
|
63
|
+
readonly SyntaxError: SyntaxErrorConstructor;
|
|
64
|
+
readonly TypeError: TypeErrorConstructor;
|
|
65
|
+
readonly URIError: URIErrorConstructor;
|
|
66
|
+
readonly AggregateError: AggregateErrorConstructor;
|
|
22
67
|
readonly AbstractFormatError: typeof AbstractFormatError;
|
|
23
68
|
readonly CsvFormatError: typeof CsvFormatError;
|
|
24
69
|
readonly CollectionError: typeof CollectionError;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ALL_ERRORS } from '../0-index';
|
|
2
2
|
/**
|
|
3
3
|
* Represents a serialized error or custom Promptbook error
|
|
4
4
|
*
|
|
@@ -8,7 +8,7 @@ export type ErrorJson = {
|
|
|
8
8
|
/**
|
|
9
9
|
* The type of the error
|
|
10
10
|
*/
|
|
11
|
-
readonly name: keyof typeof
|
|
11
|
+
readonly name: keyof typeof ALL_ERRORS;
|
|
12
12
|
/**
|
|
13
13
|
* The message of the error
|
|
14
14
|
*/
|
package/esm/typings/src/llm-providers/_common/register/createLlmToolsFromConfiguration.test.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/node",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.78.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/node.index.d.ts",
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"@promptbook/core": "0.
|
|
57
|
+
"@promptbook/core": "0.78.0-0"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"colors": "1.4.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.77.
|
|
46
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.77.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
|
|
@@ -2186,7 +2186,7 @@
|
|
|
2186
2186
|
*
|
|
2187
2187
|
* @public exported from `@promptbook/core`
|
|
2188
2188
|
*/
|
|
2189
|
-
var
|
|
2189
|
+
var PROMPTBOOK_ERRORS = {
|
|
2190
2190
|
AbstractFormatError: AbstractFormatError,
|
|
2191
2191
|
CsvFormatError: CsvFormatError,
|
|
2192
2192
|
CollectionError: CollectionError,
|
|
@@ -2204,6 +2204,35 @@
|
|
|
2204
2204
|
UnexpectedError: UnexpectedError,
|
|
2205
2205
|
// TODO: [🪑]> VersionMismatchError,
|
|
2206
2206
|
};
|
|
2207
|
+
/**
|
|
2208
|
+
* Index of all javascript errors
|
|
2209
|
+
*
|
|
2210
|
+
* @private for internal usage
|
|
2211
|
+
*/
|
|
2212
|
+
var COMMON_JAVASCRIPT_ERRORS = {
|
|
2213
|
+
Error: Error,
|
|
2214
|
+
EvalError: EvalError,
|
|
2215
|
+
RangeError: RangeError,
|
|
2216
|
+
ReferenceError: ReferenceError,
|
|
2217
|
+
SyntaxError: SyntaxError,
|
|
2218
|
+
TypeError: TypeError,
|
|
2219
|
+
URIError: URIError,
|
|
2220
|
+
AggregateError: AggregateError,
|
|
2221
|
+
/*
|
|
2222
|
+
Note: Not widely supported
|
|
2223
|
+
> InternalError,
|
|
2224
|
+
> ModuleError,
|
|
2225
|
+
> HeapError,
|
|
2226
|
+
> WebAssemblyCompileError,
|
|
2227
|
+
> WebAssemblyRuntimeError,
|
|
2228
|
+
*/
|
|
2229
|
+
};
|
|
2230
|
+
/**
|
|
2231
|
+
* Index of all errors
|
|
2232
|
+
*
|
|
2233
|
+
* @private for internal usage
|
|
2234
|
+
*/
|
|
2235
|
+
var ALL_ERRORS = __assign(__assign({}, PROMPTBOOK_ERRORS), COMMON_JAVASCRIPT_ERRORS);
|
|
2207
2236
|
/**
|
|
2208
2237
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
2209
2238
|
*/
|
|
@@ -2214,11 +2243,11 @@
|
|
|
2214
2243
|
* @public exported from `@promptbook/utils`
|
|
2215
2244
|
*/
|
|
2216
2245
|
function deserializeError(error) {
|
|
2217
|
-
|
|
2218
|
-
|
|
2246
|
+
var ErrorClass = ALL_ERRORS[error.name];
|
|
2247
|
+
if (ErrorClass === undefined) {
|
|
2248
|
+
return new Error("".concat(error.name, ": ").concat(error.message));
|
|
2219
2249
|
}
|
|
2220
|
-
|
|
2221
|
-
return new CustomError(error.message);
|
|
2250
|
+
return new ErrorClass(error.message);
|
|
2222
2251
|
}
|
|
2223
2252
|
|
|
2224
2253
|
/**
|
|
@@ -2292,8 +2321,8 @@
|
|
|
2292
2321
|
*/
|
|
2293
2322
|
function serializeError(error) {
|
|
2294
2323
|
var name = error.name, message = error.message, stack = error.stack;
|
|
2295
|
-
if (!
|
|
2296
|
-
|
|
2324
|
+
if (!Object.keys(ALL_ERRORS).includes(name)) {
|
|
2325
|
+
console.error(spaceTrim__default["default"](function (block) { return "\n \n Cannot serialize error with name \"".concat(name, "\"\n\n ").concat(block(stack || message), "\n \n "); }));
|
|
2297
2326
|
}
|
|
2298
2327
|
return {
|
|
2299
2328
|
name: name,
|
|
@@ -2308,9 +2337,9 @@
|
|
|
2308
2337
|
* @param script from which to extract the variables
|
|
2309
2338
|
* @returns the list of variable names
|
|
2310
2339
|
* @throws {ParseError} if the script is invalid
|
|
2311
|
-
* @public exported from `@promptbook/utils`
|
|
2340
|
+
* @public exported from `@promptbook/utils` <- Note: [👖] This is usable elsewhere than in Promptbook, so keeping in utils
|
|
2312
2341
|
*/
|
|
2313
|
-
function
|
|
2342
|
+
function extractVariablesFromScript(script) {
|
|
2314
2343
|
var variables = new Set();
|
|
2315
2344
|
script = "(()=>{".concat(script, "})()");
|
|
2316
2345
|
try {
|
|
@@ -2357,7 +2386,7 @@
|
|
|
2357
2386
|
* @param task the task with used parameters
|
|
2358
2387
|
* @returns the set of parameter names
|
|
2359
2388
|
* @throws {ParseError} if the script is invalid
|
|
2360
|
-
* @public exported from `@promptbook/
|
|
2389
|
+
* @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
|
|
2361
2390
|
*/
|
|
2362
2391
|
function extractParameterNamesFromTask(task) {
|
|
2363
2392
|
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
@@ -2378,7 +2407,7 @@
|
|
|
2378
2407
|
}
|
|
2379
2408
|
if (taskType === 'SCRIPT_TASK') {
|
|
2380
2409
|
try {
|
|
2381
|
-
for (var _g = __values(
|
|
2410
|
+
for (var _g = __values(extractVariablesFromScript(content)), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
2382
2411
|
var parameterName = _h.value;
|
|
2383
2412
|
parameterNames.add(parameterName);
|
|
2384
2413
|
}
|
|
@@ -8006,6 +8035,7 @@
|
|
|
8006
8035
|
var e_1, _a;
|
|
8007
8036
|
var lines = markdown.split('\n');
|
|
8008
8037
|
var sections = [];
|
|
8038
|
+
// TODO: [🧽] DRY
|
|
8009
8039
|
var currentType = 'MARKDOWN';
|
|
8010
8040
|
var buffer = [];
|
|
8011
8041
|
var finishSection = function () {
|
|
@@ -8170,7 +8200,7 @@
|
|
|
8170
8200
|
* @public exported from `@promptbook/core`
|
|
8171
8201
|
*/
|
|
8172
8202
|
function pipelineStringToJsonSync(pipelineString) {
|
|
8173
|
-
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
8203
|
+
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e;
|
|
8174
8204
|
var $pipelineJson = {
|
|
8175
8205
|
title: undefined /* <- Note: [🍙] Putting here placeholder to keep `title` on top at final JSON */,
|
|
8176
8206
|
pipelineUrl: undefined /* <- Note: Putting here placeholder to keep `pipelineUrl` on top at final JSON */,
|
|
@@ -8199,7 +8229,7 @@
|
|
|
8199
8229
|
// =============================================================
|
|
8200
8230
|
// Note: 1️⃣ Parsing of the markdown into object
|
|
8201
8231
|
if (pipelineString.startsWith('#!')) {
|
|
8202
|
-
var
|
|
8232
|
+
var _f = __read(pipelineString.split('\n')), shebangLine_1 = _f[0], restLines = _f.slice(1);
|
|
8203
8233
|
if (!(shebangLine_1 || '').includes('ptbk')) {
|
|
8204
8234
|
throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n It seems that you try to parse a book file which has non-standard shebang line for book files:\n Shebang line must contain 'ptbk'\n\n You have:\n ".concat(block(shebangLine_1 || '(empty line)'), "\n\n It should look like this:\n #!/usr/bin/env ptbk\n\n ").concat(block(getPipelineIdentification()), "\n "); }));
|
|
8205
8235
|
}
|
|
@@ -8209,7 +8239,7 @@
|
|
|
8209
8239
|
pipelineString = flattenMarkdown(pipelineString) /* <- Note: [🥞] */;
|
|
8210
8240
|
pipelineString = pipelineString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
|
|
8211
8241
|
pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
|
|
8212
|
-
var
|
|
8242
|
+
var _g = __read(splitMarkdownIntoSections(pipelineString).map(parseMarkdownSection)), pipelineHead = _g[0], pipelineSections = _g.slice(1); /* <- Note: [🥞] */
|
|
8213
8243
|
if (pipelineHead === undefined) {
|
|
8214
8244
|
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Pipeline head is not defined\n\n ".concat(block(getPipelineIdentification()), "\n\n This should never happen, because the pipeline already flattened\n "); }));
|
|
8215
8245
|
}
|
|
@@ -8300,11 +8330,41 @@
|
|
|
8300
8330
|
}
|
|
8301
8331
|
finally { if (e_1) throw e_1.error; }
|
|
8302
8332
|
}
|
|
8333
|
+
// =============================================================
|
|
8334
|
+
// Note: 4️⃣ Prepare unique section names with indexes when needed
|
|
8335
|
+
var sectionCounts = {};
|
|
8336
|
+
try {
|
|
8337
|
+
for (var pipelineSections_1 = __values(pipelineSections), pipelineSections_1_1 = pipelineSections_1.next(); !pipelineSections_1_1.done; pipelineSections_1_1 = pipelineSections_1.next()) {
|
|
8338
|
+
var section = pipelineSections_1_1.value;
|
|
8339
|
+
var name_1 = titleToName(section.title);
|
|
8340
|
+
if (sectionCounts[name_1] === undefined) {
|
|
8341
|
+
sectionCounts[name_1] = { count: 0, currentIndex: 0 };
|
|
8342
|
+
}
|
|
8343
|
+
sectionCounts[name_1].count++;
|
|
8344
|
+
}
|
|
8345
|
+
}
|
|
8346
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
8347
|
+
finally {
|
|
8348
|
+
try {
|
|
8349
|
+
if (pipelineSections_1_1 && !pipelineSections_1_1.done && (_b = pipelineSections_1.return)) _b.call(pipelineSections_1);
|
|
8350
|
+
}
|
|
8351
|
+
finally { if (e_2) throw e_2.error; }
|
|
8352
|
+
}
|
|
8353
|
+
var getUniqueSectionName = function (title) {
|
|
8354
|
+
var name = titleToName(title);
|
|
8355
|
+
var count = sectionCounts[name];
|
|
8356
|
+
if (count.count === 1) {
|
|
8357
|
+
return name;
|
|
8358
|
+
}
|
|
8359
|
+
var nameWithSuffix = "".concat(name, "-").concat(count.currentIndex);
|
|
8360
|
+
count.currentIndex++;
|
|
8361
|
+
return nameWithSuffix;
|
|
8362
|
+
};
|
|
8303
8363
|
var _loop_2 = function (section) {
|
|
8304
|
-
var
|
|
8364
|
+
var e_6, _m, e_7, _o;
|
|
8305
8365
|
// TODO: Parse section's description (the content out of the codeblock and lists)
|
|
8306
8366
|
var listItems_2 = extractAllListItemsFromMarkdown(section.content);
|
|
8307
|
-
var
|
|
8367
|
+
var _p = extractOneBlockFromMarkdown(section.content), language = _p.language, content = _p.content;
|
|
8308
8368
|
// TODO: [🎾][1] DRY description
|
|
8309
8369
|
var description_1 = section.content;
|
|
8310
8370
|
// Note: Remove codeblocks - TODO: [🎾]
|
|
@@ -8320,7 +8380,7 @@
|
|
|
8320
8380
|
isSectionTypeSet: false,
|
|
8321
8381
|
isTask: true,
|
|
8322
8382
|
taskType: undefined /* <- Note: [🍙] Putting here placeholder to keep `taskType` on top at final JSON */,
|
|
8323
|
-
name:
|
|
8383
|
+
name: getUniqueSectionName(section.title),
|
|
8324
8384
|
title: section.title,
|
|
8325
8385
|
description: description_1,
|
|
8326
8386
|
content: content,
|
|
@@ -8368,17 +8428,17 @@
|
|
|
8368
8428
|
};
|
|
8369
8429
|
try {
|
|
8370
8430
|
// TODO [♓️] List commands and before apply order them to achieve order-agnostic commands
|
|
8371
|
-
for (var commands_1 = (
|
|
8372
|
-
var
|
|
8431
|
+
for (var commands_1 = (e_6 = void 0, __values(commands)), commands_1_1 = commands_1.next(); !commands_1_1.done; commands_1_1 = commands_1.next()) {
|
|
8432
|
+
var _q = commands_1_1.value, listItem = _q.listItem, command = _q.command;
|
|
8373
8433
|
_loop_4(listItem, command);
|
|
8374
8434
|
}
|
|
8375
8435
|
}
|
|
8376
|
-
catch (
|
|
8436
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
8377
8437
|
finally {
|
|
8378
8438
|
try {
|
|
8379
|
-
if (commands_1_1 && !commands_1_1.done && (
|
|
8439
|
+
if (commands_1_1 && !commands_1_1.done && (_m = commands_1.return)) _m.call(commands_1);
|
|
8380
8440
|
}
|
|
8381
|
-
finally { if (
|
|
8441
|
+
finally { if (e_6) throw e_6.error; }
|
|
8382
8442
|
}
|
|
8383
8443
|
// TODO: [🍧] Should be done in SECTION command
|
|
8384
8444
|
if ($taskJson.taskType === 'SCRIPT_TASK') {
|
|
@@ -8392,8 +8452,8 @@
|
|
|
8392
8452
|
}
|
|
8393
8453
|
$taskJson.dependentParameterNames = Array.from(extractParameterNamesFromTask($taskJson));
|
|
8394
8454
|
try {
|
|
8395
|
-
for (var
|
|
8396
|
-
var parameterName =
|
|
8455
|
+
for (var _r = (e_7 = void 0, __values($taskJson.dependentParameterNames)), _s = _r.next(); !_s.done; _s = _r.next()) {
|
|
8456
|
+
var parameterName = _s.value;
|
|
8397
8457
|
// TODO: [🧠] This definition should be made first in the task
|
|
8398
8458
|
defineParam({
|
|
8399
8459
|
parameterName: parameterName,
|
|
@@ -8404,12 +8464,12 @@
|
|
|
8404
8464
|
});
|
|
8405
8465
|
}
|
|
8406
8466
|
}
|
|
8407
|
-
catch (
|
|
8467
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
8408
8468
|
finally {
|
|
8409
8469
|
try {
|
|
8410
|
-
if (
|
|
8470
|
+
if (_s && !_s.done && (_o = _r.return)) _o.call(_r);
|
|
8411
8471
|
}
|
|
8412
|
-
finally { if (
|
|
8472
|
+
finally { if (e_7) throw e_7.error; }
|
|
8413
8473
|
}
|
|
8414
8474
|
/*
|
|
8415
8475
|
// TODO: [🍧] This should be checked in `MODEL` command + better error message
|
|
@@ -8438,21 +8498,21 @@
|
|
|
8438
8498
|
};
|
|
8439
8499
|
try {
|
|
8440
8500
|
// =============================================================
|
|
8441
|
-
// Note:
|
|
8442
|
-
for (var
|
|
8443
|
-
var section =
|
|
8501
|
+
// Note: 5️⃣ Process each section of the pipeline
|
|
8502
|
+
for (var pipelineSections_2 = __values(pipelineSections), pipelineSections_2_1 = pipelineSections_2.next(); !pipelineSections_2_1.done; pipelineSections_2_1 = pipelineSections_2.next()) {
|
|
8503
|
+
var section = pipelineSections_2_1.value;
|
|
8444
8504
|
_loop_2(section);
|
|
8445
8505
|
}
|
|
8446
8506
|
}
|
|
8447
|
-
catch (
|
|
8507
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
8448
8508
|
finally {
|
|
8449
8509
|
try {
|
|
8450
|
-
if (
|
|
8510
|
+
if (pipelineSections_2_1 && !pipelineSections_2_1.done && (_c = pipelineSections_2.return)) _c.call(pipelineSections_2);
|
|
8451
8511
|
}
|
|
8452
|
-
finally { if (
|
|
8512
|
+
finally { if (e_3) throw e_3.error; }
|
|
8453
8513
|
}
|
|
8454
8514
|
// =============================================================
|
|
8455
|
-
// Note:
|
|
8515
|
+
// Note: 6️⃣ Mark parameters as INPUT if not explicitly set
|
|
8456
8516
|
if ($pipelineJson.parameters.every(function (parameter) { return !parameter.isInput; })) {
|
|
8457
8517
|
var _loop_3 = function (parameter) {
|
|
8458
8518
|
var isThisParameterResulting = $pipelineJson.tasks.some(function (task) { return task.resultingParameterName === parameter.name; });
|
|
@@ -8461,42 +8521,42 @@
|
|
|
8461
8521
|
}
|
|
8462
8522
|
};
|
|
8463
8523
|
try {
|
|
8464
|
-
for (var
|
|
8465
|
-
var parameter =
|
|
8524
|
+
for (var _h = __values($pipelineJson.parameters), _j = _h.next(); !_j.done; _j = _h.next()) {
|
|
8525
|
+
var parameter = _j.value;
|
|
8466
8526
|
_loop_3(parameter);
|
|
8467
8527
|
}
|
|
8468
8528
|
}
|
|
8469
|
-
catch (
|
|
8529
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
8470
8530
|
finally {
|
|
8471
8531
|
try {
|
|
8472
|
-
if (
|
|
8532
|
+
if (_j && !_j.done && (_d = _h.return)) _d.call(_h);
|
|
8473
8533
|
}
|
|
8474
|
-
finally { if (
|
|
8534
|
+
finally { if (e_4) throw e_4.error; }
|
|
8475
8535
|
}
|
|
8476
8536
|
}
|
|
8477
8537
|
// =============================================================
|
|
8478
|
-
// Note:
|
|
8538
|
+
// Note: 7️⃣ Mark all non-INPUT parameters as OUTPUT if any OUTPUT is not set
|
|
8479
8539
|
if ($pipelineJson.parameters.every(function (parameter) { return !parameter.isOutput; })) {
|
|
8480
8540
|
try {
|
|
8481
|
-
for (var
|
|
8482
|
-
var parameter =
|
|
8541
|
+
for (var _k = __values($pipelineJson.parameters), _l = _k.next(); !_l.done; _l = _k.next()) {
|
|
8542
|
+
var parameter = _l.value;
|
|
8483
8543
|
if (!parameter.isInput) {
|
|
8484
8544
|
parameter.isOutput = true;
|
|
8485
8545
|
}
|
|
8486
8546
|
}
|
|
8487
8547
|
}
|
|
8488
|
-
catch (
|
|
8548
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
8489
8549
|
finally {
|
|
8490
8550
|
try {
|
|
8491
|
-
if (
|
|
8551
|
+
if (_l && !_l.done && (_e = _k.return)) _e.call(_k);
|
|
8492
8552
|
}
|
|
8493
|
-
finally { if (
|
|
8553
|
+
finally { if (e_5) throw e_5.error; }
|
|
8494
8554
|
}
|
|
8495
8555
|
}
|
|
8496
8556
|
// =============================================================
|
|
8497
|
-
// Note:
|
|
8557
|
+
// Note: 8️⃣ Cleanup of undefined values
|
|
8498
8558
|
$pipelineJson.tasks.forEach(function (tasks) {
|
|
8499
|
-
var
|
|
8559
|
+
var e_8, _a;
|
|
8500
8560
|
try {
|
|
8501
8561
|
for (var _b = __values(Object.entries(tasks)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
8502
8562
|
var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
|
|
@@ -8505,16 +8565,16 @@
|
|
|
8505
8565
|
}
|
|
8506
8566
|
}
|
|
8507
8567
|
}
|
|
8508
|
-
catch (
|
|
8568
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
8509
8569
|
finally {
|
|
8510
8570
|
try {
|
|
8511
8571
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
8512
8572
|
}
|
|
8513
|
-
finally { if (
|
|
8573
|
+
finally { if (e_8) throw e_8.error; }
|
|
8514
8574
|
}
|
|
8515
8575
|
});
|
|
8516
8576
|
$pipelineJson.parameters.forEach(function (parameter) {
|
|
8517
|
-
var
|
|
8577
|
+
var e_9, _a;
|
|
8518
8578
|
try {
|
|
8519
8579
|
for (var _b = __values(Object.entries(parameter)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
8520
8580
|
var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
|
|
@@ -8523,12 +8583,12 @@
|
|
|
8523
8583
|
}
|
|
8524
8584
|
}
|
|
8525
8585
|
}
|
|
8526
|
-
catch (
|
|
8586
|
+
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
8527
8587
|
finally {
|
|
8528
8588
|
try {
|
|
8529
8589
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
8530
8590
|
}
|
|
8531
|
-
finally { if (
|
|
8591
|
+
finally { if (e_9) throw e_9.error; }
|
|
8532
8592
|
}
|
|
8533
8593
|
});
|
|
8534
8594
|
// =============================================================
|