@promptbook/core 0.77.1 → 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.
@@ -30,6 +30,9 @@ 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';
@@ -145,6 +148,9 @@ 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 };
@@ -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 { extractParameterNamesFromTask } from '../conversion/utils/extractParameterNamesFromTask';
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 { extractParameterNamesFromTask };
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/utils`
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
  /**
@@ -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 extractVariables(script: string_javascript): Set<string_javascript_name>;
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 {};
@@ -16,11 +16,11 @@ type RenameParameterOptions = {
16
16
  readonly newParameterName: string_name;
17
17
  };
18
18
  /**
19
- * Function `renameParameter` will find all usable parameters for given task
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/utils`
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 renameParameter(options: RenameParameterOptions): PipelineJson;
25
+ export declare function renamePipelineParameter(options: RenameParameterOptions): PipelineJson;
26
26
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/core",
3
- "version": "0.77.1",
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,
package/umd/index.umd.js CHANGED
@@ -25,7 +25,7 @@
25
25
  *
26
26
  * @see https://github.com/webgptorg/promptbook
27
27
  */
28
- var PROMPTBOOK_ENGINE_VERSION = '0.77.0';
28
+ var PROMPTBOOK_ENGINE_VERSION = '0.77.1';
29
29
  /**
30
30
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
31
31
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -2647,9 +2647,9 @@
2647
2647
  * @param script from which to extract the variables
2648
2648
  * @returns the list of variable names
2649
2649
  * @throws {ParseError} if the script is invalid
2650
- * @public exported from `@promptbook/utils`
2650
+ * @public exported from `@promptbook/utils` <- Note: [👖] This is usable elsewhere than in Promptbook, so keeping in utils
2651
2651
  */
2652
- function extractVariables(script) {
2652
+ function extractVariablesFromScript(script) {
2653
2653
  var variables = new Set();
2654
2654
  script = "(()=>{".concat(script, "})()");
2655
2655
  try {
@@ -2696,7 +2696,7 @@
2696
2696
  * @param task the task with used parameters
2697
2697
  * @returns the set of parameter names
2698
2698
  * @throws {ParseError} if the script is invalid
2699
- * @public exported from `@promptbook/utils`
2699
+ * @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
2700
2700
  */
2701
2701
  function extractParameterNamesFromTask(task) {
2702
2702
  var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
@@ -2717,7 +2717,7 @@
2717
2717
  }
2718
2718
  if (taskType === 'SCRIPT_TASK') {
2719
2719
  try {
2720
- for (var _g = __values(extractVariables(content)), _h = _g.next(); !_h.done; _h = _g.next()) {
2720
+ for (var _g = __values(extractVariablesFromScript(content)), _h = _g.next(); !_h.done; _h = _g.next()) {
2721
2721
  var parameterName = _h.value;
2722
2722
  parameterNames.add(parameterName);
2723
2723
  }
@@ -8373,6 +8373,7 @@
8373
8373
  var e_1, _a;
8374
8374
  var lines = markdown.split('\n');
8375
8375
  var sections = [];
8376
+ // TODO: [🧽] DRY
8376
8377
  var currentType = 'MARKDOWN';
8377
8378
  var buffer = [];
8378
8379
  var finishSection = function () {
@@ -9121,6 +9122,115 @@
9121
9122
  * TODO: [🕌] When more than 2 functionalities, split into separate functions
9122
9123
  */
9123
9124
 
9125
+ /**
9126
+ * Function `removePipelineCommand` will remove one command from pipeline string
9127
+ *
9128
+ * @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
9129
+ */
9130
+ function removePipelineCommand(options) {
9131
+ var e_1, _a;
9132
+ var command = options.command, pipeline = options.pipeline;
9133
+ var lines = pipeline.split('\n');
9134
+ // TODO: [🧽] DRY
9135
+ var currentType = 'MARKDOWN';
9136
+ var newLines = [];
9137
+ try {
9138
+ for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
9139
+ var line = lines_1_1.value;
9140
+ if (currentType === 'MARKDOWN') {
9141
+ if (line.startsWith('```')) {
9142
+ currentType = 'CODE_BLOCK';
9143
+ }
9144
+ else if (line.includes('<!--')) {
9145
+ currentType = 'COMMENT';
9146
+ }
9147
+ }
9148
+ else if (currentType === 'CODE_BLOCK') {
9149
+ if (line.startsWith('```')) {
9150
+ currentType = 'MARKDOWN';
9151
+ }
9152
+ }
9153
+ else if (currentType === 'COMMENT') {
9154
+ if (line.includes('-->')) {
9155
+ currentType = 'MARKDOWN';
9156
+ }
9157
+ }
9158
+ if (currentType === 'MARKDOWN' && /^(-|\d\))/m.test(line) && line.toUpperCase().includes(command)) {
9159
+ continue;
9160
+ }
9161
+ newLines.push(line);
9162
+ }
9163
+ }
9164
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
9165
+ finally {
9166
+ try {
9167
+ if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
9168
+ }
9169
+ finally { if (e_1) throw e_1.error; }
9170
+ }
9171
+ var newPipeline = spaceTrim__default["default"](newLines.join('\n'));
9172
+ return newPipeline;
9173
+ }
9174
+
9175
+ /**
9176
+ * Function `renamePipelineParameter` will find all usable parameters for given task
9177
+ * In other words, it will find all parameters that are not used in the task itseld and all its dependencies
9178
+ *
9179
+ * @throws {PipelineLogicError} If the new parameter name is already used in the pipeline
9180
+ * @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
9181
+ */
9182
+ function renamePipelineParameter(options) {
9183
+ var e_1, _a, e_2, _b;
9184
+ var pipeline = options.pipeline, oldParameterName = options.oldParameterName, newParameterName = options.newParameterName;
9185
+ if (pipeline.parameters.some(function (parameter) { return parameter.name === newParameterName; })) {
9186
+ throw new PipelineLogicError("Can not replace {".concat(oldParameterName, "} to {").concat(newParameterName, "} because {").concat(newParameterName, "} is already used in the pipeline"));
9187
+ }
9188
+ var renamedPipeline = __assign(__assign({}, pipeline), {
9189
+ // <- TODO: [🪓] This should be without `as $PipelineJson`
9190
+ parameters: __spreadArray([], __read(pipeline.parameters), false), tasks: __spreadArray([], __read(pipeline.tasks), false) });
9191
+ try {
9192
+ for (var _c = __values(renamedPipeline.parameters), _d = _c.next(); !_d.done; _d = _c.next()) {
9193
+ var parameter = _d.value;
9194
+ if (parameter.name !== oldParameterName) {
9195
+ continue;
9196
+ }
9197
+ parameter.name = newParameterName;
9198
+ }
9199
+ }
9200
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
9201
+ finally {
9202
+ try {
9203
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
9204
+ }
9205
+ finally { if (e_1) throw e_1.error; }
9206
+ }
9207
+ try {
9208
+ for (var _e = __values(renamedPipeline.tasks), _f = _e.next(); !_f.done; _f = _e.next()) {
9209
+ var task = _f.value;
9210
+ if (task.resultingParameterName === oldParameterName) {
9211
+ task.resultingParameterName = newParameterName;
9212
+ }
9213
+ task.dependentParameterNames = task.dependentParameterNames.map(function (dependentParameterName) {
9214
+ return dependentParameterName === oldParameterName ? newParameterName : dependentParameterName;
9215
+ });
9216
+ task.content = task.content.replace(new RegExp("{".concat(oldParameterName, "}"), 'g'), "{".concat(newParameterName, "}"));
9217
+ task.title = task.title.replace(new RegExp("{".concat(oldParameterName, "}"), 'g'), "{".concat(newParameterName, "}"));
9218
+ task.description =
9219
+ task.description === undefined
9220
+ ? undefined
9221
+ : task.description.replace(new RegExp("{".concat(oldParameterName, "}"), 'g'), "{".concat(newParameterName, "}"));
9222
+ }
9223
+ }
9224
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
9225
+ finally {
9226
+ try {
9227
+ if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
9228
+ }
9229
+ finally { if (e_2) throw e_2.error; }
9230
+ }
9231
+ return renamedPipeline;
9232
+ }
9233
+
9124
9234
  /**
9125
9235
  * Tests if the value is [🚉] serializable as JSON
9126
9236
  *
@@ -10779,6 +10889,7 @@
10779
10889
  exports.createSubcollection = createSubcollection;
10780
10890
  exports.embeddingVectorToString = embeddingVectorToString;
10781
10891
  exports.executionReportJsonToString = executionReportJsonToString;
10892
+ exports.extractParameterNamesFromTask = extractParameterNamesFromTask;
10782
10893
  exports.getPipelineInterface = getPipelineInterface;
10783
10894
  exports.isPassingExpectations = isPassingExpectations;
10784
10895
  exports.isPipelineImplementingInterface = isPipelineImplementingInterface;
@@ -10795,6 +10906,8 @@
10795
10906
  exports.preparePipeline = preparePipeline;
10796
10907
  exports.prepareTasks = prepareTasks;
10797
10908
  exports.prettifyPipelineString = prettifyPipelineString;
10909
+ exports.removePipelineCommand = removePipelineCommand;
10910
+ exports.renamePipelineParameter = renamePipelineParameter;
10798
10911
  exports.stringifyPipelineJson = stringifyPipelineJson;
10799
10912
  exports.unpreparePipeline = unpreparePipeline;
10800
10913
  exports.usageToHuman = usageToHuman;