@promptbook/core 0.83.0 → 0.84.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 +52 -31
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/editable.index.d.ts +8 -2
- package/esm/typings/src/utils/editable/edit-pipeline-string/addPipelineCommand.d.ts +17 -0
- package/esm/typings/src/utils/editable/edit-pipeline-string/deflatePipeline.d.ts +10 -0
- package/esm/typings/src/utils/editable/{utils → edit-pipeline-string}/removePipelineCommand.d.ts +1 -1
- package/esm/typings/src/utils/editable/edit-pipeline-string/removePipelineCommand.test.d.ts +1 -0
- package/esm/typings/src/utils/editable/utils/isFlatPipeline.d.ts +7 -0
- package/esm/typings/src/utils/editable/utils/renamePipelineParameter.d.ts +3 -0
- package/package.json +1 -1
- package/umd/index.umd.js +52 -31
- package/umd/index.umd.js.map +1 -1
- /package/esm/typings/src/utils/editable/{utils/removePipelineCommand.test.d.ts → edit-pipeline-string/addPipelineCommand.test.d.ts} +0 -0
|
@@ -36,8 +36,11 @@ import type { ActionCommand } from '../commands/X_ACTION/ActionCommand';
|
|
|
36
36
|
import { actionCommandParser } from '../commands/X_ACTION/actionCommandParser';
|
|
37
37
|
import type { InstrumentCommand } from '../commands/X_INSTRUMENT/InstrumentCommand';
|
|
38
38
|
import { instrumentCommandParser } from '../commands/X_INSTRUMENT/instrumentCommandParser';
|
|
39
|
+
import { addPipelineCommand } from '../utils/editable/edit-pipeline-string/addPipelineCommand';
|
|
40
|
+
import { deflatePipeline } from '../utils/editable/edit-pipeline-string/deflatePipeline';
|
|
41
|
+
import { removePipelineCommand } from '../utils/editable/edit-pipeline-string/removePipelineCommand';
|
|
39
42
|
import type { PipelineEditableSerialized } from '../utils/editable/types/PipelineEditableSerialized';
|
|
40
|
-
import {
|
|
43
|
+
import { isFlatPipeline } from '../utils/editable/utils/isFlatPipeline';
|
|
41
44
|
import { renamePipelineParameter } from '../utils/editable/utils/renamePipelineParameter';
|
|
42
45
|
import { stringifyPipelineJson } from '../utils/editable/utils/stringifyPipelineJson';
|
|
43
46
|
export { BOOK_LANGUAGE_VERSION, PROMPTBOOK_ENGINE_VERSION };
|
|
@@ -78,7 +81,10 @@ export type { ActionCommand };
|
|
|
78
81
|
export { actionCommandParser };
|
|
79
82
|
export type { InstrumentCommand };
|
|
80
83
|
export { instrumentCommandParser };
|
|
81
|
-
export
|
|
84
|
+
export { addPipelineCommand };
|
|
85
|
+
export { deflatePipeline };
|
|
82
86
|
export { removePipelineCommand };
|
|
87
|
+
export type { PipelineEditableSerialized };
|
|
88
|
+
export { isFlatPipeline };
|
|
83
89
|
export { renamePipelineParameter };
|
|
84
90
|
export { stringifyPipelineJson };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { PipelineString } from '../../../pipeline/PipelineString';
|
|
2
|
+
import type { string_markdown_text } from '../../../types/typeAliases';
|
|
3
|
+
type AddPipelineCommandOptions = {
|
|
4
|
+
commandString: string_markdown_text;
|
|
5
|
+
pipelineString: PipelineString;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* @@@
|
|
9
|
+
*
|
|
10
|
+
* @public exported from `@promptbook/editable`
|
|
11
|
+
*/
|
|
12
|
+
export declare function addPipelineCommand(options: AddPipelineCommandOptions): PipelineString;
|
|
13
|
+
export {};
|
|
14
|
+
/**
|
|
15
|
+
* TODO: [🧠] What is the better solution - `- xxx`, - `- xxx` or preserve (see also next TODO)
|
|
16
|
+
* TODO: When existing commands 1) as 2) number 3) list, add 4) new command as next number
|
|
17
|
+
*/
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PipelineString } from '../../../pipeline/PipelineString';
|
|
2
|
+
/**
|
|
3
|
+
* @@@
|
|
4
|
+
*
|
|
5
|
+
* @public exported from `@promptbook/editable`
|
|
6
|
+
*/
|
|
7
|
+
export declare function deflatePipeline(pipelineString: PipelineString): PipelineString;
|
|
8
|
+
/**
|
|
9
|
+
* TODO: Unit test
|
|
10
|
+
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
package/umd/index.umd.js
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
* @generated
|
|
28
28
|
* @see https://github.com/webgptorg/promptbook
|
|
29
29
|
*/
|
|
30
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.
|
|
30
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.83.0';
|
|
31
31
|
/**
|
|
32
32
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
33
33
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -8973,6 +8973,55 @@
|
|
|
8973
8973
|
var SUPPORTED_SCRIPT_LANGUAGES = ['javascript', 'typescript', 'python'];
|
|
8974
8974
|
// <- TODO: [🏥] DRY
|
|
8975
8975
|
|
|
8976
|
+
/**
|
|
8977
|
+
* Removes Markdown (or HTML) comments
|
|
8978
|
+
*
|
|
8979
|
+
* @param {string} content - The string to remove comments from.
|
|
8980
|
+
* @returns {string} The input string with all comments removed.
|
|
8981
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
8982
|
+
*/
|
|
8983
|
+
function removeMarkdownComments(content) {
|
|
8984
|
+
return spaceTrim.spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
|
|
8985
|
+
}
|
|
8986
|
+
|
|
8987
|
+
/**
|
|
8988
|
+
* @@@
|
|
8989
|
+
*
|
|
8990
|
+
* @public exported from `@promptbook/editable`
|
|
8991
|
+
*/
|
|
8992
|
+
function isFlatPipeline(pipelineString) {
|
|
8993
|
+
pipelineString = removeMarkdownComments(pipelineString);
|
|
8994
|
+
pipelineString = spaceTrim__default["default"](pipelineString);
|
|
8995
|
+
var isMarkdownBeginningWithHeadline = pipelineString.startsWith('# ');
|
|
8996
|
+
var isLastLineReturnStatement = pipelineString.split('\n').pop().split('`').join('').startsWith('->');
|
|
8997
|
+
// TODO: Also (double)check
|
|
8998
|
+
// > const usedCommands
|
|
8999
|
+
// > const isBlocksUsed
|
|
9000
|
+
// > const returnStatementCount
|
|
9001
|
+
var isFlat = !isMarkdownBeginningWithHeadline && isLastLineReturnStatement;
|
|
9002
|
+
return isFlat;
|
|
9003
|
+
}
|
|
9004
|
+
|
|
9005
|
+
/**
|
|
9006
|
+
* @@@
|
|
9007
|
+
*
|
|
9008
|
+
* @public exported from `@promptbook/editable`
|
|
9009
|
+
*/
|
|
9010
|
+
function deflatePipeline(pipelineString) {
|
|
9011
|
+
if (!isFlatPipeline(pipelineString)) {
|
|
9012
|
+
return pipelineString;
|
|
9013
|
+
}
|
|
9014
|
+
var pipelineStringLines = pipelineString.split('\n');
|
|
9015
|
+
var returnStatement = pipelineStringLines.pop();
|
|
9016
|
+
var prompt = spaceTrim__default["default"](pipelineStringLines.join('\n'));
|
|
9017
|
+
pipelineString = validatePipelineString(spaceTrim__default["default"](function (block) { return "\n # ".concat(DEFAULT_BOOK_TITLE, "\n\n ## Prompt\n\n ```\n ").concat(block(prompt), "\n ```\n\n ").concat(returnStatement, "\n "); }));
|
|
9018
|
+
// <- TODO: Maybe use book` notation
|
|
9019
|
+
return pipelineString;
|
|
9020
|
+
}
|
|
9021
|
+
/**
|
|
9022
|
+
* TODO: Unit test
|
|
9023
|
+
*/
|
|
9024
|
+
|
|
8976
9025
|
/**
|
|
8977
9026
|
* Utility function to extract all list items from markdown
|
|
8978
9027
|
*
|
|
@@ -9188,17 +9237,6 @@
|
|
|
9188
9237
|
* NOW we are working just with markdown string and its good enough
|
|
9189
9238
|
*/
|
|
9190
9239
|
|
|
9191
|
-
/**
|
|
9192
|
-
* Removes Markdown (or HTML) comments
|
|
9193
|
-
*
|
|
9194
|
-
* @param {string} content - The string to remove comments from.
|
|
9195
|
-
* @returns {string} The input string with all comments removed.
|
|
9196
|
-
* @public exported from `@promptbook/markdown-utils`
|
|
9197
|
-
*/
|
|
9198
|
-
function removeMarkdownComments(content) {
|
|
9199
|
-
return spaceTrim.spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
|
|
9200
|
-
}
|
|
9201
|
-
|
|
9202
9240
|
/**
|
|
9203
9241
|
* @@@
|
|
9204
9242
|
*
|
|
@@ -9283,26 +9321,9 @@
|
|
|
9283
9321
|
pipelineString = removeMarkdownComments(pipelineString);
|
|
9284
9322
|
pipelineString = spaceTrim.spaceTrim(pipelineString);
|
|
9285
9323
|
// <- TODO: [😧] `spaceTrim` should preserve discriminated type *(or at lease `PipelineString`)*
|
|
9324
|
+
pipelineString = deflatePipeline(pipelineString);
|
|
9286
9325
|
// ==============
|
|
9287
|
-
// Note: 1️⃣◽2️⃣
|
|
9288
|
-
var isMarkdownBeginningWithHeadline = pipelineString.startsWith('# ');
|
|
9289
|
-
var isLastLineReturnStatement = pipelineString.split('\n').pop().split('`').join('').startsWith('->');
|
|
9290
|
-
// TODO: Also (double)check
|
|
9291
|
-
// > const usedCommands
|
|
9292
|
-
// > const isBlocksUsed
|
|
9293
|
-
// > const returnStatementCount
|
|
9294
|
-
var isFlatPipeline = !isMarkdownBeginningWithHeadline && isLastLineReturnStatement;
|
|
9295
|
-
// console.log({ isMarkdownBeginningWithHeadline, isLastLineReturnStatement, isFlatPipeline });
|
|
9296
|
-
if (isFlatPipeline) {
|
|
9297
|
-
var pipelineStringLines = pipelineString.split('\n');
|
|
9298
|
-
var returnStatement_1 = pipelineStringLines.pop();
|
|
9299
|
-
var prompt_1 = spaceTrim.spaceTrim(pipelineStringLines.join('\n'));
|
|
9300
|
-
pipelineString = validatePipelineString(spaceTrim.spaceTrim(function (block) { return "\n # ".concat(DEFAULT_BOOK_TITLE, "\n\n ## Prompt\n\n ```\n ").concat(block(prompt_1), "\n ```\n\n ").concat(returnStatement_1, "\n "); }));
|
|
9301
|
-
// <- TODO: Maybe use book` notation
|
|
9302
|
-
// console.log(pipelineString);
|
|
9303
|
-
}
|
|
9304
|
-
// ==============
|
|
9305
|
-
// Note: 1️⃣◽3️⃣ Parse the markdown
|
|
9326
|
+
// Note: 1️⃣◽2️⃣ Parse the markdown
|
|
9306
9327
|
pipelineString = flattenMarkdown(pipelineString) /* <- Note: [🥞] */;
|
|
9307
9328
|
pipelineString = pipelineString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
|
|
9308
9329
|
pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
|