@promptbook/utils 0.44.0-9 → 0.44.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 +862 -2
- package/esm/index.es.js +7 -3
- package/esm/index.es.js.map +1 -1
- package/esm/typings/_packages/utils.index.d.ts +4 -2
- package/esm/typings/execution/plugins/natural-execution-tools/mocked/fakeTextToExpectations.d.ts +6 -2
- package/esm/typings/execution/plugins/script-execution-tools/javascript/JavascriptExecutionToolsOptions.d.ts +5 -1
- package/esm/typings/execution/plugins/script-execution-tools/javascript/utils/unknownToString.d.ts +7 -0
- package/esm/typings/types/Prompt.d.ts +5 -0
- package/esm/typings/types/PromptbookJson/PromptTemplateJson.d.ts +1 -0
- package/package.json +3 -3
- package/umd/index.umd.js +50 -44
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/_packages/utils.index.d.ts +4 -2
- package/umd/typings/execution/plugins/natural-execution-tools/mocked/fakeTextToExpectations.d.ts +6 -2
- package/umd/typings/execution/plugins/script-execution-tools/javascript/JavascriptExecutionToolsOptions.d.ts +5 -1
- package/umd/typings/execution/plugins/script-execution-tools/javascript/utils/unknownToString.d.ts +7 -0
- package/umd/typings/types/Prompt.d.ts +5 -0
- package/umd/typings/types/PromptbookJson/PromptTemplateJson.d.ts +1 -0
package/umd/index.umd.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('spacetrim'), require('prettier'), require('prettier/parser-html'), require('moment')) :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'prettier', 'prettier/parser-html', 'moment'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-utils"] = {}, global.
|
|
5
|
-
})(this, (function (exports,
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-utils"] = {}, global.spacetrim, global.prettier, global.parserHtml, global.moment));
|
|
5
|
+
})(this, (function (exports, spacetrim, prettier, parserHtml, moment) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
9
|
-
var spaceTrim__default = /*#__PURE__*/_interopDefaultLegacy(spaceTrim);
|
|
10
9
|
var parserHtml__default = /*#__PURE__*/_interopDefaultLegacy(parserHtml);
|
|
11
10
|
var moment__default = /*#__PURE__*/_interopDefaultLegacy(moment);
|
|
12
11
|
|
|
@@ -176,7 +175,7 @@
|
|
|
176
175
|
var UnexpectedError = /** @class */ (function (_super) {
|
|
177
176
|
__extends(UnexpectedError, _super);
|
|
178
177
|
function UnexpectedError(message) {
|
|
179
|
-
var _this = _super.call(this,
|
|
178
|
+
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 promptbook library\n\n Please report issue:\n https://github.com/webgptorg/promptbook/issues\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
|
|
180
179
|
_this.name = 'UnexpectedError';
|
|
181
180
|
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
182
181
|
return _this;
|
|
@@ -229,7 +228,7 @@
|
|
|
229
228
|
}
|
|
230
229
|
if (parent_1.parent === null /* <- Note: We are in root */) {
|
|
231
230
|
// [🌻]
|
|
232
|
-
throw new Error(
|
|
231
|
+
throw new Error(spacetrim.spaceTrim("\n The file has an invalid structure.\n The markdown file must have exactly one top-level section.\n "));
|
|
233
232
|
}
|
|
234
233
|
parent_1 = parent_1.parent;
|
|
235
234
|
}
|
|
@@ -263,7 +262,7 @@
|
|
|
263
262
|
return {
|
|
264
263
|
level: level,
|
|
265
264
|
title: title,
|
|
266
|
-
content:
|
|
265
|
+
content: spacetrim.spaceTrim(contentLines.join('\n')),
|
|
267
266
|
sections: sections.map(parsingMarkdownStructureToMarkdownStructure),
|
|
268
267
|
};
|
|
269
268
|
}
|
|
@@ -403,13 +402,13 @@
|
|
|
403
402
|
* @returns {string} The input string with all comments removed.
|
|
404
403
|
*/
|
|
405
404
|
function removeContentComments(content) {
|
|
406
|
-
return
|
|
405
|
+
return spacetrim.spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
|
|
407
406
|
}
|
|
408
407
|
|
|
409
408
|
/**
|
|
410
409
|
* The version of the Promptbook library
|
|
411
410
|
*/
|
|
412
|
-
var PROMPTBOOK_VERSION = '0.44.0-
|
|
411
|
+
var PROMPTBOOK_VERSION = '0.44.0-23';
|
|
413
412
|
|
|
414
413
|
/**
|
|
415
414
|
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
@@ -454,7 +453,7 @@
|
|
|
454
453
|
if (!(error instanceof Error)) {
|
|
455
454
|
throw error;
|
|
456
455
|
}
|
|
457
|
-
throw new PromptbookSyntaxError(
|
|
456
|
+
throw new PromptbookSyntaxError(spacetrim.spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.name), ": ").concat(block(error.message), "\n "); }));
|
|
458
457
|
}
|
|
459
458
|
return variables;
|
|
460
459
|
}
|
|
@@ -602,15 +601,15 @@
|
|
|
602
601
|
type.startsWith('PROMPTBOOKURL') ||
|
|
603
602
|
type.startsWith('HTTPS')) {
|
|
604
603
|
if (!(listItemParts.length === 2 || (listItemParts.length === 1 && type.startsWith('HTTPS')))) {
|
|
605
|
-
throw new PromptbookSyntaxError(
|
|
604
|
+
throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n ")));
|
|
606
605
|
}
|
|
607
606
|
var promptbookUrlString = listItemParts.pop();
|
|
608
607
|
var promptbookUrl = new URL(promptbookUrlString);
|
|
609
608
|
if (promptbookUrl.protocol !== 'https:') {
|
|
610
|
-
throw new PromptbookSyntaxError(
|
|
609
|
+
throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n Protocol must be HTTPS\n ")));
|
|
611
610
|
}
|
|
612
611
|
if (promptbookUrl.hash !== '') {
|
|
613
|
-
throw new PromptbookSyntaxError(
|
|
612
|
+
throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n URL must not contain hash\n Hash is used for identification of the prompt template in the pipeline\n ")));
|
|
614
613
|
}
|
|
615
614
|
return {
|
|
616
615
|
type: 'PROMPTBOOK_URL',
|
|
@@ -619,7 +618,7 @@
|
|
|
619
618
|
}
|
|
620
619
|
else if (type.startsWith('PROMPTBOOK_VERSION') || type.startsWith('PTBK_VERSION')) {
|
|
621
620
|
if (listItemParts.length !== 2) {
|
|
622
|
-
throw new PromptbookSyntaxError(
|
|
621
|
+
throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid PROMPTBOOK_VERSION command:\n\n - ".concat(listItem, "\n ")));
|
|
623
622
|
}
|
|
624
623
|
var promptbookVersion = listItemParts.pop();
|
|
625
624
|
// TODO: Validate version
|
|
@@ -634,7 +633,7 @@
|
|
|
634
633
|
type.startsWith('SIMPLE_TEMPLATE')) {
|
|
635
634
|
var executionTypes = ExecutionTypes.filter(function (executionType) { return type.includes(executionType); });
|
|
636
635
|
if (executionTypes.length !== 1) {
|
|
637
|
-
throw new PromptbookSyntaxError(
|
|
636
|
+
throw new PromptbookSyntaxError(spacetrim.spaceTrim(function (block) { return "\n Unknown execution type in command:\n\n - ".concat(listItem, "\n\n Supported execution types are:\n ").concat(block(ExecutionTypes.join(', ')), "\n "); }));
|
|
638
637
|
}
|
|
639
638
|
return {
|
|
640
639
|
type: 'EXECUTE',
|
|
@@ -659,7 +658,7 @@
|
|
|
659
658
|
};
|
|
660
659
|
}
|
|
661
660
|
else {
|
|
662
|
-
throw new PromptbookSyntaxError(
|
|
661
|
+
throw new PromptbookSyntaxError(spacetrim.spaceTrim(function (block) { return "\n Unknown model variant in command:\n\n - ".concat(listItem, "\n\n Supported variants are:\n ").concat(block(['CHAT', 'COMPLETION'].join(', ')), "\n "); }));
|
|
663
662
|
}
|
|
664
663
|
}
|
|
665
664
|
if (type.startsWith('MODEL_NAME')) {
|
|
@@ -670,7 +669,7 @@
|
|
|
670
669
|
};
|
|
671
670
|
}
|
|
672
671
|
else {
|
|
673
|
-
throw new PromptbookSyntaxError(
|
|
672
|
+
throw new PromptbookSyntaxError(spacetrim.spaceTrim(function (block) { return "\n Unknown model key in command:\n\n - ".concat(listItem, "\n\n Supported model keys are:\n ").concat(block(['variant', 'name'].join(', ')), "\n\n Example:\n\n - MODEL VARIANT Chat\n - MODEL NAME gpt-4\n "); }));
|
|
674
673
|
}
|
|
675
674
|
}
|
|
676
675
|
else if (type.startsWith('PARAM') ||
|
|
@@ -680,12 +679,12 @@
|
|
|
680
679
|
listItem.startsWith('> {') /* <- Note: This is a bit hack to parse return parameters defined at the end of each section */) {
|
|
681
680
|
var parametersMatch = listItem.match(/\{(?<parameterName>[a-z0-9_]+)\}[^\S\r\n]*(?<parameterDescription>.*)$/im);
|
|
682
681
|
if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
|
|
683
|
-
throw new PromptbookSyntaxError(
|
|
682
|
+
throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
|
|
684
683
|
}
|
|
685
684
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
686
685
|
var _b = parametersMatch.groups, parameterName = _b.parameterName, parameterDescription = _b.parameterDescription;
|
|
687
686
|
if (parameterDescription && parameterDescription.match(/\{(?<parameterName>[a-z0-9_]+)\}/im)) {
|
|
688
|
-
throw new PromptbookSyntaxError(
|
|
687
|
+
throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Parameter {".concat(parameterName, "} can not contain another parameter in description:\n\n - ").concat(listItem, "\n ")));
|
|
689
688
|
}
|
|
690
689
|
var isInput = type.startsWith('INPUT');
|
|
691
690
|
var isOutput = type.startsWith('OUTPUT');
|
|
@@ -703,11 +702,11 @@
|
|
|
703
702
|
}
|
|
704
703
|
else if (type.startsWith('JOKER')) {
|
|
705
704
|
if (listItemParts.length !== 2) {
|
|
706
|
-
throw new PromptbookSyntaxError(
|
|
705
|
+
throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid JOKER command:\n\n - ".concat(listItem, "\n ")));
|
|
707
706
|
}
|
|
708
707
|
var parametersMatch = (listItemParts.pop() || '').match(/^\{(?<parameterName>[a-z0-9_]+)\}$/im);
|
|
709
708
|
if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
|
|
710
|
-
throw new PromptbookSyntaxError(
|
|
709
|
+
throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
|
|
711
710
|
}
|
|
712
711
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
713
712
|
var parameterName = parametersMatch.groups.parameterName;
|
|
@@ -718,7 +717,7 @@
|
|
|
718
717
|
}
|
|
719
718
|
else if (type.startsWith('POSTPROCESS') || type.startsWith('POST_PROCESS')) {
|
|
720
719
|
if (listItemParts.length !== 2) {
|
|
721
|
-
throw new PromptbookSyntaxError(
|
|
720
|
+
throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid POSTPROCESSING command:\n\n - ".concat(listItem, "\n ")));
|
|
722
721
|
}
|
|
723
722
|
var functionName = listItemParts.pop();
|
|
724
723
|
return {
|
|
@@ -798,7 +797,7 @@
|
|
|
798
797
|
if (!(error instanceof Error)) {
|
|
799
798
|
throw error;
|
|
800
799
|
}
|
|
801
|
-
throw new PromptbookSyntaxError(
|
|
800
|
+
throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid EXPECT command; ".concat(error.message, ":\n\n - ").concat(listItem, "\n ")));
|
|
802
801
|
}
|
|
803
802
|
/*
|
|
804
803
|
} else if (type.startsWith('__________________')) {
|
|
@@ -806,7 +805,7 @@
|
|
|
806
805
|
*/
|
|
807
806
|
}
|
|
808
807
|
else {
|
|
809
|
-
throw new PromptbookSyntaxError(
|
|
808
|
+
throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Unknown command:\n\n - ".concat(listItem, "\n\n Supported commands are:\n - PROMPTBOOK_URL <url>\n - PROMPTBOOK_VERSION <version>\n - EXECUTE PROMPT TEMPLATE\n - EXECUTE SIMPLE TEMPLATE\n - SIMPLE TEMPLATE\n - EXECUTE SCRIPT\n - EXECUTE PROMPT_DIALOG'\n - PROMPT_DIALOG'\n - MODEL NAME <name>\n - MODEL VARIANT <\"Chat\"|\"Completion\">\n - INPUT PARAM {<name>} <description>\n - OUTPUT PARAM {<name>} <description>\n - POSTPROCESS `{functionName}`\n - JOKER {<name>}\n - EXPECT JSON\n - EXPECT <\"Exactly\"|\"Min\"|\"Max\"> <number> <\"Chars\"|\"Words\"|\"Sentences\"|\"Paragraphs\"|\"Pages\">\n\n ")));
|
|
810
809
|
}
|
|
811
810
|
}
|
|
812
811
|
|
|
@@ -842,7 +841,7 @@
|
|
|
842
841
|
existingParameter.description &&
|
|
843
842
|
existingParameter.description !== parameterDescription &&
|
|
844
843
|
parameterDescription) {
|
|
845
|
-
throw new PromptbookSyntaxError(
|
|
844
|
+
throw new PromptbookSyntaxError(spacetrim.spaceTrim(function (block) { return "\n Parameter {".concat(parameterName, "} is defined multiple times with different description.\n\n First definition:\n ").concat(block(existingParameter.description || '[undefined]'), "\n\n Second definition:\n ").concat(block(parameterDescription || '[undefined]'), "\n "); }));
|
|
846
845
|
}
|
|
847
846
|
if (existingParameter) {
|
|
848
847
|
if (parameterDescription) {
|
|
@@ -863,7 +862,7 @@
|
|
|
863
862
|
var markdownStructure = markdownToMarkdownStructure(promptbookString);
|
|
864
863
|
var markdownStructureDeepness = countMarkdownStructureDeepness(markdownStructure);
|
|
865
864
|
if (markdownStructureDeepness !== 2) {
|
|
866
|
-
throw new PromptbookSyntaxError(
|
|
865
|
+
throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid markdown structure.\n The markdown must have exactly 2 levels of headings (one top-level section and one section for each template).\n Now it has ".concat(markdownStructureDeepness, " levels of headings.\n ")));
|
|
867
866
|
}
|
|
868
867
|
promptbookJson.title = markdownStructure.title;
|
|
869
868
|
// TODO: [1] DRY description
|
|
@@ -872,7 +871,7 @@
|
|
|
872
871
|
description = description.split(/^```.*^```/gms).join('');
|
|
873
872
|
//Note: Remove lists and return statement
|
|
874
873
|
description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
875
|
-
description =
|
|
874
|
+
description = spacetrim.spaceTrim(description);
|
|
876
875
|
if (description === '') {
|
|
877
876
|
description = undefined;
|
|
878
877
|
}
|
|
@@ -987,13 +986,13 @@
|
|
|
987
986
|
throw new PromptbookSyntaxError('You must specify the language of the script in the prompt template');
|
|
988
987
|
}
|
|
989
988
|
else if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
|
|
990
|
-
throw new PromptbookSyntaxError(
|
|
989
|
+
throw new PromptbookSyntaxError(spacetrim.spaceTrim(function (block) { return "\n Script language ".concat(language, " is not supported.\n\n Supported languages are:\n ").concat(block(SUPPORTED_SCRIPT_LANGUAGES.join(', ')), "\n\n "); }));
|
|
991
990
|
}
|
|
992
991
|
}
|
|
993
992
|
var lastLine = section.content.split('\n').pop();
|
|
994
993
|
var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
|
|
995
994
|
if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
|
|
996
|
-
throw new PromptbookSyntaxError(
|
|
995
|
+
throw new PromptbookSyntaxError(spacetrim.spaceTrim(function (block) { return "\n Invalid template - each section must end with \"-> {...}\"\n\n Invalid section:\n ".concat(block(
|
|
997
996
|
// TODO: Show code of invalid sections each time + DRY
|
|
998
997
|
section.content
|
|
999
998
|
.split('\n')
|
|
@@ -1007,7 +1006,7 @@
|
|
|
1007
1006
|
description_1 = description_1.split(/^```.*^```/gms).join('');
|
|
1008
1007
|
//Note: Remove lists and return statement
|
|
1009
1008
|
description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
1010
|
-
description_1 =
|
|
1009
|
+
description_1 = spacetrim.spaceTrim(description_1);
|
|
1011
1010
|
if (description_1 === '') {
|
|
1012
1011
|
description_1 = undefined;
|
|
1013
1012
|
}
|
|
@@ -1098,7 +1097,7 @@
|
|
|
1098
1097
|
var sectionRegex = new RegExp("<!--".concat(sectionName, "-->([\\s\\S]*?)<!--/").concat(sectionName, "-->"), 'g');
|
|
1099
1098
|
var sectionMatch = content.match(sectionRegex);
|
|
1100
1099
|
if (sectionMatch) {
|
|
1101
|
-
return content.replace(sectionRegex,
|
|
1100
|
+
return content.replace(sectionRegex, spacetrim.spaceTrim(function (block) { return "\n <!--".concat(sectionName, "-->\n ").concat(block(warningLine), "\n ").concat(block(sectionContent), "\n <!--/").concat(sectionName, "-->\n "); }));
|
|
1102
1101
|
}
|
|
1103
1102
|
var placeForSection = removeContentComments(content).match(/^##.*$/im);
|
|
1104
1103
|
if (!placeForSection) {
|
|
@@ -1161,7 +1160,7 @@
|
|
|
1161
1160
|
}
|
|
1162
1161
|
return 'template' + normalizeTo_PascalCase(template.title);
|
|
1163
1162
|
};
|
|
1164
|
-
var promptbookMermaid_1 =
|
|
1163
|
+
var promptbookMermaid_1 = spacetrim.spaceTrim(function (block) { return "\n\n %% \uD83D\uDD2E Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually\n\n flowchart LR\n subgraph \"".concat(promptbookJson_1.title, "\"\n\n direction TB\n\n input((Input)):::input\n ").concat(block(promptbookJson_1.promptTemplates
|
|
1165
1164
|
.flatMap(function (_a) {
|
|
1166
1165
|
var title = _a.title, dependentParameterNames = _a.dependentParameterNames, resultingParameterName = _a.resultingParameterName;
|
|
1167
1166
|
return __spreadArray([
|
|
@@ -1180,7 +1179,7 @@
|
|
|
1180
1179
|
return "".concat(parameterNameToTemplateName_1(name), "--\"{").concat(name, "}\"-->output");
|
|
1181
1180
|
})
|
|
1182
1181
|
.join('\n')), "\n output((Output)):::output\n\n classDef input color: grey;\n classDef output color: grey;\n\n end;\n\n\n\n "); });
|
|
1183
|
-
var promptbookMermaidBlock =
|
|
1182
|
+
var promptbookMermaidBlock = spacetrim.spaceTrim(function (block) { return "\n ```mermaid\n ".concat(block(promptbookMermaid_1), "\n ```\n "); });
|
|
1184
1183
|
promptbookString = addAutoGeneratedSection(promptbookString, {
|
|
1185
1184
|
sectionName: 'Graph',
|
|
1186
1185
|
sectionContent: promptbookMermaidBlock,
|
|
@@ -1228,7 +1227,7 @@
|
|
|
1228
1227
|
throw errors[0];
|
|
1229
1228
|
}
|
|
1230
1229
|
else {
|
|
1231
|
-
throw new PromptbookExecutionError(
|
|
1230
|
+
throw new PromptbookExecutionError(spacetrim.spaceTrim(function (block) { return "\n Multiple errors occurred during promptnook execution\n\n ".concat(block(errors.map(function (error) { return '- ' + error.message; }).join('\n')), "\n "); }));
|
|
1232
1231
|
}
|
|
1233
1232
|
}
|
|
1234
1233
|
/**
|
|
@@ -1893,7 +1892,7 @@
|
|
|
1893
1892
|
var e_1, _a;
|
|
1894
1893
|
var _b, _c, _d, _e, _f, _g;
|
|
1895
1894
|
var _h = __assign(__assign({}, ExecutionReportStringOptionsDefaults), (options || {})), taxRate = _h.taxRate, chartsWidth = _h.chartsWidth;
|
|
1896
|
-
var executionReportString =
|
|
1895
|
+
var executionReportString = spacetrim.spaceTrim(function (block) { return "\n # ".concat(executionReportJson.title || 'Execution report', "\n\n ").concat(block(executionReportJson.description || ''), "\n "); });
|
|
1897
1896
|
var headerList = [];
|
|
1898
1897
|
if (executionReportJson.promptbookUrl) {
|
|
1899
1898
|
headerList.push("PROMPTBOOK URL ".concat(executionReportJson.promptbookUrl));
|
|
@@ -2010,17 +2009,17 @@
|
|
|
2010
2009
|
if (just(true)) {
|
|
2011
2010
|
executionReportString +=
|
|
2012
2011
|
'\n\n\n\n' +
|
|
2013
|
-
|
|
2012
|
+
spacetrim.spaceTrim(function (block) { return "\n\n ### Prompt\n\n ```\n ".concat(block(escapeMarkdownBlock(promptExecution.prompt.content)), "\n ```\n\n "); });
|
|
2014
2013
|
}
|
|
2015
2014
|
if (promptExecution.result && promptExecution.result.content) {
|
|
2016
2015
|
executionReportString +=
|
|
2017
2016
|
'\n\n\n\n' +
|
|
2018
|
-
|
|
2017
|
+
spacetrim.spaceTrim(function (block) { return "\n\n ### Result\n\n ```\n ".concat(block(escapeMarkdownBlock(promptExecution.result.content)), "\n ```\n "); });
|
|
2019
2018
|
}
|
|
2020
2019
|
if (promptExecution.error && promptExecution.error.message) {
|
|
2021
2020
|
executionReportString +=
|
|
2022
2021
|
'\n\n\n\n' +
|
|
2023
|
-
|
|
2022
|
+
spacetrim.spaceTrim(function (block) { return "\n\n ### Error\n\n ```\n ".concat(block(escapeMarkdownBlock(promptExecution.error.message)), "\n ```\n\n "); });
|
|
2024
2023
|
}
|
|
2025
2024
|
};
|
|
2026
2025
|
try {
|
|
@@ -2415,13 +2414,13 @@
|
|
|
2415
2414
|
*
|
|
2416
2415
|
*/
|
|
2417
2416
|
function trimCodeBlock(value) {
|
|
2418
|
-
value =
|
|
2417
|
+
value = spacetrim.spaceTrim(value);
|
|
2419
2418
|
if (!/^```[a-z]*(.*)```$/is.test(value)) {
|
|
2420
2419
|
return value;
|
|
2421
2420
|
}
|
|
2422
2421
|
value = value.replace(/^```[a-z]*/i, '');
|
|
2423
2422
|
value = value.replace(/```$/i, '');
|
|
2424
|
-
value =
|
|
2423
|
+
value = spacetrim.spaceTrim(value);
|
|
2425
2424
|
return value;
|
|
2426
2425
|
}
|
|
2427
2426
|
|
|
@@ -2432,9 +2431,9 @@
|
|
|
2432
2431
|
* if you want to start code block in the prompt but you don't want to end it in the result.
|
|
2433
2432
|
*/
|
|
2434
2433
|
function trimEndOfCodeBlock(value) {
|
|
2435
|
-
value =
|
|
2434
|
+
value = spacetrim.spaceTrim(value);
|
|
2436
2435
|
value = value.replace(/```$/g, '');
|
|
2437
|
-
value =
|
|
2436
|
+
value = spacetrim.spaceTrim(value);
|
|
2438
2437
|
return value;
|
|
2439
2438
|
}
|
|
2440
2439
|
|
|
@@ -2455,7 +2454,7 @@
|
|
|
2455
2454
|
var trimmedText = text;
|
|
2456
2455
|
// Remove leading and trailing spaces and newlines
|
|
2457
2456
|
if (isTrimmed) {
|
|
2458
|
-
trimmedText =
|
|
2457
|
+
trimmedText = spacetrim.spaceTrim(trimmedText);
|
|
2459
2458
|
}
|
|
2460
2459
|
var processedText = trimmedText;
|
|
2461
2460
|
if (isIntroduceSentenceRemoved) {
|
|
@@ -2464,7 +2463,7 @@
|
|
|
2464
2463
|
// Remove the introduce sentence and quotes by replacing it with an empty string
|
|
2465
2464
|
processedText = processedText.replace(introduceSentenceRegex, '');
|
|
2466
2465
|
}
|
|
2467
|
-
processedText =
|
|
2466
|
+
processedText = spacetrim.spaceTrim(processedText);
|
|
2468
2467
|
}
|
|
2469
2468
|
if (processedText.length < 3) {
|
|
2470
2469
|
return trimmedText;
|
|
@@ -2511,16 +2510,23 @@
|
|
|
2511
2510
|
|
|
2512
2511
|
// And the normalization (originally n12 library) utilities:
|
|
2513
2512
|
var normalizeTo = {
|
|
2513
|
+
// [🕙] lowercase: normalizeTo_lowercase,
|
|
2514
|
+
// [🕙] UPPERCASE: normalizeTo_UPPERCASE,
|
|
2514
2515
|
camelCase: normalizeTo_camelCase,
|
|
2515
2516
|
PascalCase: normalizeTo_PascalCase,
|
|
2516
|
-
|
|
2517
|
+
SCREAMING_CASE: normalizeTo_SCREAMING_CASE,
|
|
2517
2518
|
snake_case: normalizeTo_snake_case,
|
|
2518
2519
|
'kebab-case': normalizeToKebabCase,
|
|
2519
2520
|
};
|
|
2520
2521
|
/**
|
|
2521
2522
|
* TODO: [🧠] Maybe create some indipendent package like `markdown-tools` from both here exported and @private utilities
|
|
2523
|
+
* Note: [🕙] It does not make sence to have simple lower / UPPER case normalization
|
|
2522
2524
|
*/
|
|
2523
2525
|
|
|
2526
|
+
Object.defineProperty(exports, 'spaceTrim', {
|
|
2527
|
+
enumerable: true,
|
|
2528
|
+
get: function () { return spacetrim.spaceTrim; }
|
|
2529
|
+
});
|
|
2524
2530
|
exports.CountUtils = CountUtils;
|
|
2525
2531
|
exports.DIACRITIC_VARIANTS_LETTERS = DIACRITIC_VARIANTS_LETTERS;
|
|
2526
2532
|
exports.ExecutionReportStringOptionsDefaults = ExecutionReportStringOptionsDefaults;
|