@promptbook/cli 0.58.0 → 0.59.0-1
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 +1 -1
- package/esm/index.es.js +371 -332
- package/esm/index.es.js.map +1 -1
- package/esm/typings/_packages/core.index.d.ts +9 -10
- package/esm/typings/_packages/node.index.d.ts +1 -1
- package/esm/typings/_packages/types.index.d.ts +11 -70
- package/esm/typings/conversion/prettify/prettifyPromptbookString.d.ts +1 -1
- package/esm/typings/conversion/promptbookStringToJson.d.ts +17 -2
- package/esm/typings/execution/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +1 -1
- package/esm/typings/execution/translation/automatic-translate/automatic-translators/TranslatorOptions.d.ts +1 -1
- package/esm/typings/expectations/drafts/isDomainNameFree.d.ts +6 -0
- package/esm/typings/expectations/drafts/isGithubNameFree.d.ts +6 -0
- package/esm/typings/formats/_common/FormatDefinition.d.ts +20 -4
- package/esm/typings/formats/csv/ListFormatDefinition.d.ts +11 -0
- package/esm/typings/formats/json/JsonFormatDefinition.d.ts +5 -1
- package/esm/typings/formats/list/ListFormatDefinition.d.ts +13 -0
- package/esm/typings/formats/xml/XmlFormatDefinition.d.ts +4 -0
- package/{umd/typings/knowledgebase → esm/typings/knowledge}/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +1 -1
- package/esm/typings/knowledge/prepare-knowledge/_common/IndexPreparer.d.ts +4 -0
- package/esm/typings/knowledge/prepare-knowledge/markdown/playground/markdown-knowledge-playground.d.ts +2 -0
- package/esm/typings/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +7 -0
- package/esm/typings/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +16 -0
- package/esm/typings/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +2 -1
- package/esm/typings/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +1 -1
- package/esm/typings/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +1 -1
- package/esm/typings/llm-providers/openai/OpenAiExecutionTools.d.ts +1 -1
- package/esm/typings/llm-providers/remote/interfaces/RemoteServerOptions.d.ts +1 -1
- package/{umd/typings/library → esm/typings/promptbook-library}/constructors/createPromptbookLibraryFromDirectory.d.ts +3 -0
- package/esm/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromPromise.d.ts +3 -0
- package/{umd/typings/library → esm/typings/promptbook-library}/constructors/createPromptbookLibraryFromSources.d.ts +4 -1
- package/esm/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromUrl.d.ts +3 -0
- package/esm/typings/scripting/python/PythonExecutionTools.d.ts +1 -1
- package/esm/typings/scripting/typescript/TypescriptExecutionTools.d.ts +1 -1
- package/esm/typings/types/PromptbookJson/KnowledgeJson.d.ts +6 -0
- package/esm/typings/types/PromptbookJson/MaterialKnowledgePieceJson.d.ts +27 -0
- package/esm/typings/types/PromptbookJson/PromptbookJson.d.ts +8 -6
- package/esm/typings/types/typeAliases.d.ts +7 -1
- package/package.json +4 -4
- package/umd/index.umd.js +371 -332
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/_packages/core.index.d.ts +9 -10
- package/umd/typings/_packages/node.index.d.ts +1 -1
- package/umd/typings/_packages/types.index.d.ts +11 -70
- package/umd/typings/conversion/prettify/prettifyPromptbookString.d.ts +1 -1
- package/umd/typings/conversion/promptbookStringToJson.d.ts +17 -2
- package/umd/typings/execution/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +1 -1
- package/umd/typings/execution/translation/automatic-translate/automatic-translators/TranslatorOptions.d.ts +1 -1
- package/umd/typings/expectations/drafts/isDomainNameFree.d.ts +6 -0
- package/umd/typings/expectations/drafts/isGithubNameFree.d.ts +6 -0
- package/umd/typings/formats/_common/FormatDefinition.d.ts +20 -4
- package/umd/typings/formats/csv/ListFormatDefinition.d.ts +11 -0
- package/umd/typings/formats/json/JsonFormatDefinition.d.ts +5 -1
- package/umd/typings/formats/list/ListFormatDefinition.d.ts +13 -0
- package/umd/typings/formats/xml/XmlFormatDefinition.d.ts +4 -0
- package/{esm/typings/knowledgebase → umd/typings/knowledge}/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +1 -1
- package/umd/typings/knowledge/prepare-knowledge/_common/IndexPreparer.d.ts +4 -0
- package/umd/typings/knowledge/prepare-knowledge/markdown/playground/markdown-knowledge-playground.d.ts +2 -0
- package/umd/typings/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +7 -0
- package/umd/typings/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +16 -0
- package/umd/typings/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +2 -1
- package/umd/typings/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +1 -1
- package/umd/typings/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +1 -1
- package/umd/typings/llm-providers/openai/OpenAiExecutionTools.d.ts +1 -1
- package/umd/typings/llm-providers/remote/interfaces/RemoteServerOptions.d.ts +1 -1
- package/{esm/typings/library → umd/typings/promptbook-library}/constructors/createPromptbookLibraryFromDirectory.d.ts +3 -0
- package/umd/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromPromise.d.ts +3 -0
- package/{esm/typings/library → umd/typings/promptbook-library}/constructors/createPromptbookLibraryFromSources.d.ts +4 -1
- package/umd/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromUrl.d.ts +3 -0
- package/umd/typings/scripting/python/PythonExecutionTools.d.ts +1 -1
- package/umd/typings/scripting/typescript/TypescriptExecutionTools.d.ts +1 -1
- package/umd/typings/types/PromptbookJson/KnowledgeJson.d.ts +6 -0
- package/umd/typings/types/PromptbookJson/MaterialKnowledgePieceJson.d.ts +27 -0
- package/umd/typings/types/PromptbookJson/PromptbookJson.d.ts +8 -6
- package/umd/typings/types/typeAliases.d.ts +7 -1
- package/esm/typings/execution/plugins/script-execution-tools/postprocessing.test.d.ts +0 -1
- package/esm/typings/execution/plugins/script-execution-tools/script-execution-errors.test.d.ts +0 -1
- package/esm/typings/execution/plugins/script-execution-tools/script-execution-tools.test.d.ts +0 -1
- package/umd/typings/execution/plugins/script-execution-tools/custom-function-async.test.ts.test.d.ts +0 -1
- package/umd/typings/execution/plugins/script-execution-tools/custom-function-missing.test.d.ts +0 -1
- package/umd/typings/execution/plugins/script-execution-tools/custom-function-with-dependencies.test.d.ts +0 -1
- package/umd/typings/execution/plugins/script-execution-tools/custom-function.test.d.ts +0 -1
- package/umd/typings/execution/plugins/script-execution-tools/postprocessing.test.d.ts +0 -1
- package/umd/typings/execution/plugins/script-execution-tools/script-execution-errors.test.d.ts +0 -1
- package/umd/typings/execution/plugins/script-execution-tools/script-execution-tools.test.d.ts +0 -1
- /package/esm/typings/{knowledgebase → knowledge}/dialogs/callback/CallbackInterfaceTools.d.ts +0 -0
- /package/esm/typings/{knowledgebase → knowledge}/dialogs/callback/CallbackInterfaceToolsOptions.d.ts +0 -0
- /package/esm/typings/{knowledgebase → knowledge}/dialogs/user-interface-execution-tools.test.d.ts +0 -0
- /package/esm/typings/{execution/plugins/script-execution-tools/custom-function-async.test.ts.test.d.ts → knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.test.d.ts} +0 -0
- /package/esm/typings/{execution/plugins/script-execution-tools/custom-function-missing.test.d.ts → knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.test.d.ts} +0 -0
- /package/esm/typings/{library → promptbook-library}/PromptbookLibrary.d.ts +0 -0
- /package/esm/typings/{library → promptbook-library}/SimplePromptbookLibrary.d.ts +0 -0
- /package/esm/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromDirectory.test.d.ts +0 -0
- /package/esm/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromPromise.test.d.ts +0 -0
- /package/esm/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromSources.test.d.ts +0 -0
- /package/esm/typings/{library → promptbook-library}/constructors/createPromptbookSublibrary.d.ts +0 -0
- /package/esm/typings/{library → promptbook-library}/constructors/justTestFsImport.d.ts +0 -0
- /package/umd/typings/{knowledgebase → knowledge}/dialogs/callback/CallbackInterfaceTools.d.ts +0 -0
- /package/umd/typings/{knowledgebase → knowledge}/dialogs/callback/CallbackInterfaceToolsOptions.d.ts +0 -0
- /package/umd/typings/{knowledgebase → knowledge}/dialogs/user-interface-execution-tools.test.d.ts +0 -0
- /package/{esm/typings/execution/plugins/script-execution-tools/custom-function-with-dependencies.test.d.ts → umd/typings/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.test.d.ts} +0 -0
- /package/{esm/typings/execution/plugins/script-execution-tools/custom-function.test.d.ts → umd/typings/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.test.d.ts} +0 -0
- /package/umd/typings/{library → promptbook-library}/PromptbookLibrary.d.ts +0 -0
- /package/umd/typings/{library → promptbook-library}/SimplePromptbookLibrary.d.ts +0 -0
- /package/umd/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromDirectory.test.d.ts +0 -0
- /package/umd/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromPromise.test.d.ts +0 -0
- /package/umd/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromSources.test.d.ts +0 -0
- /package/umd/typings/{library → promptbook-library}/constructors/createPromptbookSublibrary.d.ts +0 -0
- /package/umd/typings/{library → promptbook-library}/constructors/justTestFsImport.d.ts +0 -0
package/umd/index.umd.js
CHANGED
|
@@ -146,7 +146,70 @@
|
|
|
146
146
|
/**
|
|
147
147
|
* The version of the Promptbook library
|
|
148
148
|
*/
|
|
149
|
-
var PROMPTBOOK_VERSION = '0.
|
|
149
|
+
var PROMPTBOOK_VERSION = '0.59.0-0';
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Removes HTML or Markdown comments from a string.
|
|
153
|
+
*
|
|
154
|
+
* @param {string} content - The string to remove comments from.
|
|
155
|
+
* @returns {string} The input string with all comments removed.
|
|
156
|
+
*/
|
|
157
|
+
function removeContentComments(content) {
|
|
158
|
+
return spacetrim.spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Add or modify an auto-generated section in a markdown file
|
|
163
|
+
*
|
|
164
|
+
* @private within the library
|
|
165
|
+
*/
|
|
166
|
+
function addAutoGeneratedSection(content, options) {
|
|
167
|
+
var sectionName = options.sectionName, sectionContent = options.sectionContent;
|
|
168
|
+
var warningLine = "<!-- \u26A0\uFE0F WARNING: This section was auto-generated -->";
|
|
169
|
+
var sectionRegex = new RegExp("<!--".concat(sectionName, "-->([\\s\\S]*?)<!--/").concat(sectionName, "-->"), 'g');
|
|
170
|
+
var sectionMatch = content.match(sectionRegex);
|
|
171
|
+
if (sectionMatch) {
|
|
172
|
+
return content.replace(sectionRegex, spacetrim.spaceTrim(function (block) { return "\n <!--".concat(sectionName, "-->\n ").concat(block(warningLine), "\n ").concat(block(sectionContent), "\n <!--/").concat(sectionName, "-->\n "); }));
|
|
173
|
+
}
|
|
174
|
+
var placeForSection = removeContentComments(content).match(/^##.*$/im);
|
|
175
|
+
if (!placeForSection) {
|
|
176
|
+
throw new Error("No place where to put the section <!--".concat(sectionName, "-->"));
|
|
177
|
+
}
|
|
178
|
+
var _a = __read(placeForSection, 1), heading = _a[0];
|
|
179
|
+
return content.replace(heading, "<!--".concat(sectionName, "-->\n").concat(warningLine, "\n").concat(sectionContent, "\n<!--/").concat(sectionName, "-->\n\n").concat(heading));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Prettify the html code
|
|
184
|
+
*
|
|
185
|
+
* @param content raw html code
|
|
186
|
+
* @returns formatted html code
|
|
187
|
+
*/
|
|
188
|
+
function prettifyMarkdown(content) {
|
|
189
|
+
try {
|
|
190
|
+
return prettier.format(content, {
|
|
191
|
+
parser: 'markdown',
|
|
192
|
+
plugins: [parserHtml__default["default"]],
|
|
193
|
+
// TODO: DRY - make some import or auto-copy of .prettierrc
|
|
194
|
+
endOfLine: 'lf',
|
|
195
|
+
tabWidth: 4,
|
|
196
|
+
singleQuote: true,
|
|
197
|
+
trailingComma: 'all',
|
|
198
|
+
arrowParens: 'always',
|
|
199
|
+
printWidth: 120,
|
|
200
|
+
htmlWhitespaceSensitivity: 'ignore',
|
|
201
|
+
jsxBracketSameLine: false,
|
|
202
|
+
bracketSpacing: true,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
console.error('There was an error with prettifying the markdown, using the original as the fallback', {
|
|
207
|
+
error: error,
|
|
208
|
+
html: content,
|
|
209
|
+
});
|
|
210
|
+
return content;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
150
213
|
|
|
151
214
|
/**
|
|
152
215
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
@@ -162,6 +225,15 @@
|
|
|
162
225
|
return PromptbookSyntaxError;
|
|
163
226
|
}(Error));
|
|
164
227
|
|
|
228
|
+
// import prepareKnowledgeFromMarkdownStringPromptbook from './prepare-knowledge-from-markdown.ptbk.md';
|
|
229
|
+
function prepareKnowledgeFromMarkdown(options) {
|
|
230
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
231
|
+
return __generator(this, function (_a) {
|
|
232
|
+
return [2 /*return*/, []];
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
|
|
165
237
|
/**
|
|
166
238
|
* Supported script languages
|
|
167
239
|
*/
|
|
@@ -422,16 +494,6 @@
|
|
|
422
494
|
* TODO: [🍓][🌻] !!! Decide of this is internal util, external util OR validator/postprocessor
|
|
423
495
|
*/
|
|
424
496
|
|
|
425
|
-
/**
|
|
426
|
-
* Removes HTML or Markdown comments from a string.
|
|
427
|
-
*
|
|
428
|
-
* @param {string} content - The string to remove comments from.
|
|
429
|
-
* @returns {string} The input string with all comments removed.
|
|
430
|
-
*/
|
|
431
|
-
function removeContentComments(content) {
|
|
432
|
-
return spacetrim.spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
|
|
433
|
-
}
|
|
434
|
-
|
|
435
497
|
/**
|
|
436
498
|
* Creates a new set with all elements that are present in either set
|
|
437
499
|
*/
|
|
@@ -1339,250 +1401,267 @@
|
|
|
1339
1401
|
}
|
|
1340
1402
|
|
|
1341
1403
|
/**
|
|
1342
|
-
*
|
|
1404
|
+
* Compile promptbook from string (markdown) format to JSON format
|
|
1343
1405
|
*
|
|
1406
|
+
* @param promptbookString {Promptbook} in string markdown format (.ptbk.md)
|
|
1407
|
+
* @param options - Options and tools for the compilation
|
|
1408
|
+
* @returns {Promptbook} compiled in JSON format (.ptbk.json)
|
|
1344
1409
|
* @throws {PromptbookSyntaxError} if the promptbook string is not valid
|
|
1345
1410
|
*
|
|
1346
1411
|
* Note: This function does not validate logic of the pipeline only the syntax
|
|
1412
|
+
* Note: This function acts as compilation process
|
|
1347
1413
|
*/
|
|
1348
|
-
function promptbookStringToJson(promptbookString) {
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
}
|
|
1388
|
-
};
|
|
1389
|
-
// =============================================================
|
|
1390
|
-
// Note: 3️⃣ Parse the dynamic part - the template pipeline
|
|
1391
|
-
var markdownStructure = markdownToMarkdownStructure(promptbookString);
|
|
1392
|
-
var markdownStructureDeepness = countMarkdownStructureDeepness(markdownStructure);
|
|
1393
|
-
if (markdownStructureDeepness !== 2) {
|
|
1394
|
-
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 ")));
|
|
1395
|
-
}
|
|
1396
|
-
promptbookJson.title = markdownStructure.title;
|
|
1397
|
-
// TODO: [1] DRY description
|
|
1398
|
-
var description = markdownStructure.content;
|
|
1399
|
-
// Note: Remove codeblocks
|
|
1400
|
-
description = description.split(/^```.*^```/gms).join('');
|
|
1401
|
-
//Note: Remove lists and return statement
|
|
1402
|
-
description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
1403
|
-
description = spacetrim.spaceTrim(description);
|
|
1404
|
-
if (description === '') {
|
|
1405
|
-
description = undefined;
|
|
1406
|
-
}
|
|
1407
|
-
promptbookJson.description = description;
|
|
1408
|
-
var defaultModelRequirements = {};
|
|
1409
|
-
var listItems = extractAllListItemsFromMarkdown(markdownStructure.content);
|
|
1410
|
-
try {
|
|
1411
|
-
for (var listItems_1 = __values(listItems), listItems_1_1 = listItems_1.next(); !listItems_1_1.done; listItems_1_1 = listItems_1.next()) {
|
|
1412
|
-
var listItem = listItems_1_1.value;
|
|
1413
|
-
var command = parseCommand(listItem);
|
|
1414
|
-
switch (command.type) {
|
|
1415
|
-
case 'PROMPTBOOK_URL':
|
|
1416
|
-
promptbookJson.promptbookUrl = command.promptbookUrl.href;
|
|
1417
|
-
break;
|
|
1418
|
-
case 'PROMPTBOOK_VERSION':
|
|
1419
|
-
promptbookJson.promptbookVersion = command.promptbookVersion;
|
|
1420
|
-
break;
|
|
1421
|
-
case 'MODEL':
|
|
1422
|
-
defaultModelRequirements[command.key] = command.value;
|
|
1423
|
-
break;
|
|
1424
|
-
case 'PARAMETER':
|
|
1425
|
-
addParam(command);
|
|
1426
|
-
break;
|
|
1427
|
-
default:
|
|
1428
|
-
throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the head of the promptbook ONLY at the prompt template block"));
|
|
1429
|
-
}
|
|
1430
|
-
}
|
|
1431
|
-
}
|
|
1432
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1433
|
-
finally {
|
|
1434
|
-
try {
|
|
1435
|
-
if (listItems_1_1 && !listItems_1_1.done && (_a = listItems_1.return)) _a.call(listItems_1);
|
|
1436
|
-
}
|
|
1437
|
-
finally { if (e_1) throw e_1.error; }
|
|
1438
|
-
}
|
|
1439
|
-
var _loop_1 = function (section) {
|
|
1440
|
-
var e_3, _e;
|
|
1441
|
-
// TODO: Parse prompt template description (the content out of the codeblock and lists)
|
|
1442
|
-
var templateModelRequirements = __assign({}, defaultModelRequirements);
|
|
1443
|
-
var listItems_3 = extractAllListItemsFromMarkdown(section.content);
|
|
1444
|
-
var dependentParameterNames = new Set();
|
|
1445
|
-
var executionType = 'PROMPT_TEMPLATE';
|
|
1446
|
-
var jokers = [];
|
|
1447
|
-
var postprocessing = [];
|
|
1448
|
-
var expectAmount = {};
|
|
1449
|
-
var expectFormat = undefined;
|
|
1450
|
-
var isExecutionTypeChanged = false;
|
|
1451
|
-
try {
|
|
1452
|
-
for (var listItems_2 = (e_3 = void 0, __values(listItems_3)), listItems_2_1 = listItems_2.next(); !listItems_2_1.done; listItems_2_1 = listItems_2.next()) {
|
|
1453
|
-
var listItem = listItems_2_1.value;
|
|
1454
|
-
var command = parseCommand(listItem);
|
|
1455
|
-
switch (command.type) {
|
|
1456
|
-
case 'JOKER':
|
|
1457
|
-
jokers.push(command.parameterName);
|
|
1458
|
-
dependentParameterNames.add(command.parameterName);
|
|
1459
|
-
break;
|
|
1460
|
-
case 'EXECUTE':
|
|
1461
|
-
if (isExecutionTypeChanged) {
|
|
1462
|
-
throw new PromptbookSyntaxError('Execution type is already defined in the prompt template. It can be defined only once.');
|
|
1414
|
+
function promptbookStringToJson(promptbookString, options) {
|
|
1415
|
+
if (options === void 0) { options = {}; }
|
|
1416
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1417
|
+
var llmTools, promptbookJson, knowledge, addParam, markdownStructure, markdownStructureDeepness, description, defaultModelRequirements, listItems, listItems_1, listItems_1_1, listItem, command, _loop_1, _a, _b, section;
|
|
1418
|
+
var e_1, _c, e_2, _d;
|
|
1419
|
+
return __generator(this, function (_e) {
|
|
1420
|
+
switch (_e.label) {
|
|
1421
|
+
case 0:
|
|
1422
|
+
llmTools = options.llmTools;
|
|
1423
|
+
promptbookJson = {
|
|
1424
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1425
|
+
title: undefined /* <- Note: Putting here placeholder to keep `title` on top at final JSON */,
|
|
1426
|
+
promptbookUrl: undefined /* <- Note: Putting here placeholder to keep `promptbookUrl` on top at final JSON */,
|
|
1427
|
+
promptbookVersion: PROMPTBOOK_VERSION,
|
|
1428
|
+
description: undefined /* <- Note: Putting here placeholder to keep `description` on top at final JSON */,
|
|
1429
|
+
parameters: [],
|
|
1430
|
+
promptTemplates: [],
|
|
1431
|
+
knowledge: [],
|
|
1432
|
+
};
|
|
1433
|
+
if (!llmTools) return [3 /*break*/, 2];
|
|
1434
|
+
return [4 /*yield*/, prepareKnowledgeFromMarkdown()];
|
|
1435
|
+
case 1:
|
|
1436
|
+
knowledge = _e.sent();
|
|
1437
|
+
console.info('!!!! knowledge', knowledge);
|
|
1438
|
+
_e.label = 2;
|
|
1439
|
+
case 2:
|
|
1440
|
+
// =============================================================
|
|
1441
|
+
// Note: 1️⃣ Normalization of the PROMPTBOOK string
|
|
1442
|
+
promptbookString = removeContentComments(promptbookString);
|
|
1443
|
+
promptbookString = promptbookString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
|
|
1444
|
+
promptbookString = promptbookString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
|
|
1445
|
+
addParam = function (parameterCommand) {
|
|
1446
|
+
var parameterName = parameterCommand.parameterName, parameterDescription = parameterCommand.parameterDescription, isInput = parameterCommand.isInput, isOutput = parameterCommand.isOutput;
|
|
1447
|
+
var existingParameter = promptbookJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
|
|
1448
|
+
if (existingParameter &&
|
|
1449
|
+
existingParameter.description &&
|
|
1450
|
+
existingParameter.description !== parameterDescription &&
|
|
1451
|
+
parameterDescription) {
|
|
1452
|
+
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 "); }));
|
|
1463
1453
|
}
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
case 'MODEL':
|
|
1468
|
-
templateModelRequirements[command.key] = command.value;
|
|
1469
|
-
break;
|
|
1470
|
-
case 'PARAMETER':
|
|
1471
|
-
// Note: This is just for detecting resulitng parameter name
|
|
1472
|
-
addParam(command);
|
|
1473
|
-
break;
|
|
1474
|
-
case 'POSTPROCESS':
|
|
1475
|
-
postprocessing.push(command.functionName);
|
|
1476
|
-
break;
|
|
1477
|
-
case 'EXPECT_AMOUNT':
|
|
1478
|
-
// eslint-disable-next-line no-case-declarations
|
|
1479
|
-
var unit = command.unit.toLowerCase();
|
|
1480
|
-
expectAmount[unit] = expectAmount[unit] || {};
|
|
1481
|
-
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
1482
|
-
if (expectAmount[unit].min !== undefined) {
|
|
1483
|
-
throw new PromptbookSyntaxError("Already defined minumum ".concat(expectAmount[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
1454
|
+
if (existingParameter) {
|
|
1455
|
+
if (parameterDescription) {
|
|
1456
|
+
existingParameter.description = parameterDescription;
|
|
1484
1457
|
}
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1458
|
+
}
|
|
1459
|
+
else {
|
|
1460
|
+
promptbookJson.parameters.push({
|
|
1461
|
+
name: parameterName,
|
|
1462
|
+
description: parameterDescription || undefined,
|
|
1463
|
+
isInput: isInput,
|
|
1464
|
+
isOutput: isOutput,
|
|
1465
|
+
});
|
|
1466
|
+
}
|
|
1467
|
+
};
|
|
1468
|
+
markdownStructure = markdownToMarkdownStructure(promptbookString);
|
|
1469
|
+
markdownStructureDeepness = countMarkdownStructureDeepness(markdownStructure);
|
|
1470
|
+
if (markdownStructureDeepness !== 2) {
|
|
1471
|
+
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 ")));
|
|
1472
|
+
}
|
|
1473
|
+
promptbookJson.title = markdownStructure.title;
|
|
1474
|
+
description = markdownStructure.content;
|
|
1475
|
+
// Note: Remove codeblocks
|
|
1476
|
+
description = description.split(/^```.*^```/gms).join('');
|
|
1477
|
+
//Note: Remove lists and return statement
|
|
1478
|
+
description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
1479
|
+
description = spacetrim.spaceTrim(description);
|
|
1480
|
+
if (description === '') {
|
|
1481
|
+
description = undefined;
|
|
1482
|
+
}
|
|
1483
|
+
promptbookJson.description = description;
|
|
1484
|
+
defaultModelRequirements = {};
|
|
1485
|
+
listItems = extractAllListItemsFromMarkdown(markdownStructure.content);
|
|
1486
|
+
try {
|
|
1487
|
+
for (listItems_1 = __values(listItems), listItems_1_1 = listItems_1.next(); !listItems_1_1.done; listItems_1_1 = listItems_1.next()) {
|
|
1488
|
+
listItem = listItems_1_1.value;
|
|
1489
|
+
command = parseCommand(listItem);
|
|
1490
|
+
switch (command.type) {
|
|
1491
|
+
case 'PROMPTBOOK_URL':
|
|
1492
|
+
promptbookJson.promptbookUrl = command.promptbookUrl.href;
|
|
1493
|
+
break;
|
|
1494
|
+
case 'PROMPTBOOK_VERSION':
|
|
1495
|
+
promptbookJson.promptbookVersion = command.promptbookVersion;
|
|
1496
|
+
break;
|
|
1497
|
+
case 'MODEL':
|
|
1498
|
+
defaultModelRequirements[command.key] = command.value;
|
|
1499
|
+
break;
|
|
1500
|
+
case 'PARAMETER':
|
|
1501
|
+
addParam(command);
|
|
1502
|
+
break;
|
|
1503
|
+
default:
|
|
1504
|
+
throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the head of the promptbook ONLY at the prompt template block"));
|
|
1490
1505
|
}
|
|
1491
|
-
expectAmount[unit].max = command.amount;
|
|
1492
1506
|
}
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1507
|
+
}
|
|
1508
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1509
|
+
finally {
|
|
1510
|
+
try {
|
|
1511
|
+
if (listItems_1_1 && !listItems_1_1.done && (_c = listItems_1.return)) _c.call(listItems_1);
|
|
1497
1512
|
}
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1513
|
+
finally { if (e_1) throw e_1.error; }
|
|
1514
|
+
}
|
|
1515
|
+
_loop_1 = function (section) {
|
|
1516
|
+
var e_3, _f;
|
|
1517
|
+
// TODO: Parse prompt template description (the content out of the codeblock and lists)
|
|
1518
|
+
var templateModelRequirements = __assign({}, defaultModelRequirements);
|
|
1519
|
+
var listItems_3 = extractAllListItemsFromMarkdown(section.content);
|
|
1520
|
+
var dependentParameterNames = new Set();
|
|
1521
|
+
var executionType = 'PROMPT_TEMPLATE';
|
|
1522
|
+
var jokers = [];
|
|
1523
|
+
var postprocessing = [];
|
|
1524
|
+
var expectAmount = {};
|
|
1525
|
+
var expectFormat = undefined;
|
|
1526
|
+
var isExecutionTypeChanged = false;
|
|
1527
|
+
try {
|
|
1528
|
+
for (var listItems_2 = (e_3 = void 0, __values(listItems_3)), listItems_2_1 = listItems_2.next(); !listItems_2_1.done; listItems_2_1 = listItems_2.next()) {
|
|
1529
|
+
var listItem = listItems_2_1.value;
|
|
1530
|
+
var command = parseCommand(listItem);
|
|
1531
|
+
switch (command.type) {
|
|
1532
|
+
case 'JOKER':
|
|
1533
|
+
jokers.push(command.parameterName);
|
|
1534
|
+
dependentParameterNames.add(command.parameterName);
|
|
1535
|
+
break;
|
|
1536
|
+
case 'EXECUTE':
|
|
1537
|
+
if (isExecutionTypeChanged) {
|
|
1538
|
+
throw new PromptbookSyntaxError('Execution type is already defined in the prompt template. It can be defined only once.');
|
|
1539
|
+
}
|
|
1540
|
+
executionType = command.executionType;
|
|
1541
|
+
isExecutionTypeChanged = true;
|
|
1542
|
+
break;
|
|
1543
|
+
case 'MODEL':
|
|
1544
|
+
templateModelRequirements[command.key] = command.value;
|
|
1545
|
+
break;
|
|
1546
|
+
case 'PARAMETER':
|
|
1547
|
+
// Note: This is just for detecting resulitng parameter name
|
|
1548
|
+
addParam(command);
|
|
1549
|
+
break;
|
|
1550
|
+
case 'POSTPROCESS':
|
|
1551
|
+
postprocessing.push(command.functionName);
|
|
1552
|
+
break;
|
|
1553
|
+
case 'EXPECT_AMOUNT':
|
|
1554
|
+
// eslint-disable-next-line no-case-declarations
|
|
1555
|
+
var unit = command.unit.toLowerCase();
|
|
1556
|
+
expectAmount[unit] = expectAmount[unit] || {};
|
|
1557
|
+
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
1558
|
+
if (expectAmount[unit].min !== undefined) {
|
|
1559
|
+
throw new PromptbookSyntaxError("Already defined minumum ".concat(expectAmount[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
1560
|
+
}
|
|
1561
|
+
expectAmount[unit].min = command.amount;
|
|
1562
|
+
} /* not else */
|
|
1563
|
+
if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
|
|
1564
|
+
if (expectAmount[unit].max !== undefined) {
|
|
1565
|
+
throw new PromptbookSyntaxError("Already defined maximum ".concat(expectAmount[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
1566
|
+
}
|
|
1567
|
+
expectAmount[unit].max = command.amount;
|
|
1568
|
+
}
|
|
1569
|
+
break;
|
|
1570
|
+
case 'EXPECT_FORMAT':
|
|
1571
|
+
if (expectFormat !== undefined && command.format !== expectFormat) {
|
|
1572
|
+
throw new PromptbookSyntaxError("Expect format is already defined to \"".concat(expectFormat, "\". Now you try to redefine it by \"").concat(command.format, "\"."));
|
|
1573
|
+
}
|
|
1574
|
+
expectFormat = command.format;
|
|
1575
|
+
break;
|
|
1576
|
+
default:
|
|
1577
|
+
throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the block of the prompt template ONLY at the head of the promptbook"));
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
1582
|
+
finally {
|
|
1583
|
+
try {
|
|
1584
|
+
if (listItems_2_1 && !listItems_2_1.done && (_f = listItems_2.return)) _f.call(listItems_2);
|
|
1585
|
+
}
|
|
1586
|
+
finally { if (e_3) throw e_3.error; }
|
|
1587
|
+
}
|
|
1588
|
+
var _g = extractOneBlockFromMarkdown(section.content), language = _g.language, content = _g.content;
|
|
1589
|
+
if (executionType === 'SCRIPT') {
|
|
1590
|
+
if (!language) {
|
|
1591
|
+
throw new PromptbookSyntaxError('You must specify the language of the script in the prompt template');
|
|
1592
|
+
}
|
|
1593
|
+
else if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
|
|
1594
|
+
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 "); }));
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
var lastLine = section.content.split('\n').pop();
|
|
1598
|
+
var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
|
|
1599
|
+
if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
|
|
1600
|
+
throw new PromptbookSyntaxError(spacetrim.spaceTrim(function (block) { return "\n Invalid template - each section must end with \"-> {...}\"\n\n Invalid section:\n ".concat(block(
|
|
1601
|
+
// TODO: Show code of invalid sections each time + DRY
|
|
1602
|
+
section.content
|
|
1603
|
+
.split('\n')
|
|
1604
|
+
.map(function (line) { return "> ".concat(line); })
|
|
1605
|
+
.join('\n')), "\n "); }));
|
|
1606
|
+
}
|
|
1607
|
+
var resultingParameterName = match.groups.resultingParamName;
|
|
1608
|
+
// TODO: [1] DRY description
|
|
1609
|
+
var description_1 = section.content;
|
|
1610
|
+
// Note: Remove codeblocks
|
|
1611
|
+
description_1 = description_1.split(/^```.*^```/gms).join('');
|
|
1612
|
+
//Note: Remove lists and return statement
|
|
1613
|
+
description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
1614
|
+
description_1 = spacetrim.spaceTrim(description_1);
|
|
1615
|
+
if (description_1 === '') {
|
|
1616
|
+
description_1 = undefined;
|
|
1617
|
+
}
|
|
1618
|
+
if (Object.keys(jokers).length === 0) {
|
|
1619
|
+
jokers = undefined;
|
|
1620
|
+
}
|
|
1621
|
+
if (Object.keys(expectAmount).length === 0) {
|
|
1622
|
+
expectAmount = undefined;
|
|
1623
|
+
}
|
|
1624
|
+
if (Object.keys(postprocessing).length === 0) {
|
|
1625
|
+
postprocessing = undefined;
|
|
1626
|
+
}
|
|
1627
|
+
dependentParameterNames = union(dependentParameterNames, extractParametersFromPromptTemplate(__assign(__assign({}, section), { description: description_1, executionType: executionType, content: content })));
|
|
1628
|
+
if (templateModelRequirements.modelVariant === undefined) {
|
|
1629
|
+
templateModelRequirements.modelVariant = 'CHAT';
|
|
1630
|
+
}
|
|
1631
|
+
promptbookJson.promptTemplates.push({
|
|
1632
|
+
name: titleToName(section.title),
|
|
1633
|
+
title: section.title,
|
|
1634
|
+
description: description_1,
|
|
1635
|
+
dependentParameterNames: Array.from(dependentParameterNames),
|
|
1636
|
+
executionType: executionType,
|
|
1637
|
+
jokers: jokers,
|
|
1638
|
+
postprocessing: postprocessing,
|
|
1639
|
+
expectations: expectAmount,
|
|
1640
|
+
expectFormat: expectFormat,
|
|
1641
|
+
modelRequirements: templateModelRequirements,
|
|
1642
|
+
contentLanguage: executionType === 'SCRIPT' ? language : undefined,
|
|
1643
|
+
content: content,
|
|
1644
|
+
resultingParameterName: resultingParameterName,
|
|
1645
|
+
});
|
|
1646
|
+
};
|
|
1647
|
+
try {
|
|
1648
|
+
for (_a = __values(markdownStructure.sections), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
1649
|
+
section = _b.value;
|
|
1650
|
+
_loop_1(section);
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1654
|
+
finally {
|
|
1655
|
+
try {
|
|
1656
|
+
if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
|
|
1657
|
+
}
|
|
1658
|
+
finally { if (e_2) throw e_2.error; }
|
|
1659
|
+
}
|
|
1660
|
+
// =============================================================
|
|
1661
|
+
return [2 /*return*/, promptbookJson];
|
|
1519
1662
|
}
|
|
1520
|
-
}
|
|
1521
|
-
var lastLine = section.content.split('\n').pop();
|
|
1522
|
-
var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
|
|
1523
|
-
if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
|
|
1524
|
-
throw new PromptbookSyntaxError(spacetrim.spaceTrim(function (block) { return "\n Invalid template - each section must end with \"-> {...}\"\n\n Invalid section:\n ".concat(block(
|
|
1525
|
-
// TODO: Show code of invalid sections each time + DRY
|
|
1526
|
-
section.content
|
|
1527
|
-
.split('\n')
|
|
1528
|
-
.map(function (line) { return "> ".concat(line); })
|
|
1529
|
-
.join('\n')), "\n "); }));
|
|
1530
|
-
}
|
|
1531
|
-
var resultingParameterName = match.groups.resultingParamName;
|
|
1532
|
-
// TODO: [1] DRY description
|
|
1533
|
-
var description_1 = section.content;
|
|
1534
|
-
// Note: Remove codeblocks
|
|
1535
|
-
description_1 = description_1.split(/^```.*^```/gms).join('');
|
|
1536
|
-
//Note: Remove lists and return statement
|
|
1537
|
-
description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
1538
|
-
description_1 = spacetrim.spaceTrim(description_1);
|
|
1539
|
-
if (description_1 === '') {
|
|
1540
|
-
description_1 = undefined;
|
|
1541
|
-
}
|
|
1542
|
-
if (Object.keys(jokers).length === 0) {
|
|
1543
|
-
jokers = undefined;
|
|
1544
|
-
}
|
|
1545
|
-
if (Object.keys(expectAmount).length === 0) {
|
|
1546
|
-
expectAmount = undefined;
|
|
1547
|
-
}
|
|
1548
|
-
if (Object.keys(postprocessing).length === 0) {
|
|
1549
|
-
postprocessing = undefined;
|
|
1550
|
-
}
|
|
1551
|
-
dependentParameterNames = union(dependentParameterNames, extractParametersFromPromptTemplate(__assign(__assign({}, section), { description: description_1, executionType: executionType, content: content })));
|
|
1552
|
-
if (templateModelRequirements.modelVariant === undefined) {
|
|
1553
|
-
templateModelRequirements.modelVariant = 'CHAT';
|
|
1554
|
-
}
|
|
1555
|
-
promptbookJson.promptTemplates.push({
|
|
1556
|
-
name: titleToName(section.title),
|
|
1557
|
-
title: section.title,
|
|
1558
|
-
description: description_1,
|
|
1559
|
-
dependentParameterNames: Array.from(dependentParameterNames),
|
|
1560
|
-
executionType: executionType,
|
|
1561
|
-
jokers: jokers,
|
|
1562
|
-
postprocessing: postprocessing,
|
|
1563
|
-
expectations: expectAmount,
|
|
1564
|
-
expectFormat: expectFormat,
|
|
1565
|
-
modelRequirements: templateModelRequirements,
|
|
1566
|
-
contentLanguage: executionType === 'SCRIPT' ? language : undefined,
|
|
1567
|
-
content: content,
|
|
1568
|
-
resultingParameterName: resultingParameterName,
|
|
1569
1663
|
});
|
|
1570
|
-
};
|
|
1571
|
-
try {
|
|
1572
|
-
for (var _c = __values(markdownStructure.sections), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
1573
|
-
var section = _d.value;
|
|
1574
|
-
_loop_1(section);
|
|
1575
|
-
}
|
|
1576
|
-
}
|
|
1577
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1578
|
-
finally {
|
|
1579
|
-
try {
|
|
1580
|
-
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
1581
|
-
}
|
|
1582
|
-
finally { if (e_2) throw e_2.error; }
|
|
1583
|
-
}
|
|
1584
|
-
// =============================================================
|
|
1585
|
-
return promptbookJson;
|
|
1664
|
+
});
|
|
1586
1665
|
}
|
|
1587
1666
|
/**
|
|
1588
1667
|
* TODO: Report here line/column of error
|
|
@@ -1590,59 +1669,6 @@
|
|
|
1590
1669
|
* TODO: [🧠] Parameter flags - isInput, isOutput, isInternal
|
|
1591
1670
|
*/
|
|
1592
1671
|
|
|
1593
|
-
/**
|
|
1594
|
-
* Add or modify an auto-generated section in a markdown file
|
|
1595
|
-
*
|
|
1596
|
-
* @private within the library
|
|
1597
|
-
*/
|
|
1598
|
-
function addAutoGeneratedSection(content, options) {
|
|
1599
|
-
var sectionName = options.sectionName, sectionContent = options.sectionContent;
|
|
1600
|
-
var warningLine = "<!-- \u26A0\uFE0F WARNING: This section was auto-generated -->";
|
|
1601
|
-
var sectionRegex = new RegExp("<!--".concat(sectionName, "-->([\\s\\S]*?)<!--/").concat(sectionName, "-->"), 'g');
|
|
1602
|
-
var sectionMatch = content.match(sectionRegex);
|
|
1603
|
-
if (sectionMatch) {
|
|
1604
|
-
return content.replace(sectionRegex, spacetrim.spaceTrim(function (block) { return "\n <!--".concat(sectionName, "-->\n ").concat(block(warningLine), "\n ").concat(block(sectionContent), "\n <!--/").concat(sectionName, "-->\n "); }));
|
|
1605
|
-
}
|
|
1606
|
-
var placeForSection = removeContentComments(content).match(/^##.*$/im);
|
|
1607
|
-
if (!placeForSection) {
|
|
1608
|
-
throw new Error("No place where to put the section <!--".concat(sectionName, "-->"));
|
|
1609
|
-
}
|
|
1610
|
-
var _a = __read(placeForSection, 1), heading = _a[0];
|
|
1611
|
-
return content.replace(heading, "<!--".concat(sectionName, "-->\n").concat(warningLine, "\n").concat(sectionContent, "\n<!--/").concat(sectionName, "-->\n\n").concat(heading));
|
|
1612
|
-
}
|
|
1613
|
-
|
|
1614
|
-
/**
|
|
1615
|
-
* Prettify the html code
|
|
1616
|
-
*
|
|
1617
|
-
* @param content raw html code
|
|
1618
|
-
* @returns formatted html code
|
|
1619
|
-
*/
|
|
1620
|
-
function prettifyMarkdown(content) {
|
|
1621
|
-
try {
|
|
1622
|
-
return prettier.format(content, {
|
|
1623
|
-
parser: 'markdown',
|
|
1624
|
-
plugins: [parserHtml__default["default"]],
|
|
1625
|
-
// TODO: DRY - make some import or auto-copy of .prettierrc
|
|
1626
|
-
endOfLine: 'lf',
|
|
1627
|
-
tabWidth: 4,
|
|
1628
|
-
singleQuote: true,
|
|
1629
|
-
trailingComma: 'all',
|
|
1630
|
-
arrowParens: 'always',
|
|
1631
|
-
printWidth: 120,
|
|
1632
|
-
htmlWhitespaceSensitivity: 'ignore',
|
|
1633
|
-
jsxBracketSameLine: false,
|
|
1634
|
-
bracketSpacing: true,
|
|
1635
|
-
});
|
|
1636
|
-
}
|
|
1637
|
-
catch (error) {
|
|
1638
|
-
console.error('There was an error with prettifying the markdown, using the original as the fallback', {
|
|
1639
|
-
error: error,
|
|
1640
|
-
html: content,
|
|
1641
|
-
});
|
|
1642
|
-
return content;
|
|
1643
|
-
}
|
|
1644
|
-
}
|
|
1645
|
-
|
|
1646
1672
|
/* tslint:disable */
|
|
1647
1673
|
function normalizeTo_camelCase(sentence, __firstLetterCapital) {
|
|
1648
1674
|
var e_1, _a;
|
|
@@ -1760,24 +1786,35 @@
|
|
|
1760
1786
|
* Prettyfies Promptbook string and adds Mermaid graph
|
|
1761
1787
|
*/
|
|
1762
1788
|
function prettifyPromptbookString(promptbookString, options) {
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1789
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1790
|
+
var isGraphAdded, isPrettifyed, promptbookJson, promptbookMermaid_1, promptbookMermaidBlock;
|
|
1791
|
+
return __generator(this, function (_a) {
|
|
1792
|
+
switch (_a.label) {
|
|
1793
|
+
case 0:
|
|
1794
|
+
isGraphAdded = options.isGraphAdded, isPrettifyed = options.isPrettifyed;
|
|
1795
|
+
if (!isGraphAdded) return [3 /*break*/, 2];
|
|
1796
|
+
return [4 /*yield*/, promptbookStringToJson(promptbookString /* , {!!!!} */)];
|
|
1797
|
+
case 1:
|
|
1798
|
+
promptbookJson = _a.sent();
|
|
1799
|
+
promptbookMermaid_1 = renderPromptbookMermaid(promptbookJson, {
|
|
1800
|
+
linkPromptTemplate: function (promptTemplate) {
|
|
1801
|
+
return { href: "#".concat(promptTemplate.name), title: promptTemplate.title };
|
|
1802
|
+
},
|
|
1803
|
+
});
|
|
1804
|
+
promptbookMermaidBlock = spacetrim.spaceTrim(function (block) { return "\n ```mermaid\n ".concat(block(promptbookMermaid_1), "\n ```\n "); });
|
|
1805
|
+
promptbookString = addAutoGeneratedSection(promptbookString, {
|
|
1806
|
+
sectionName: 'Graph',
|
|
1807
|
+
sectionContent: promptbookMermaidBlock,
|
|
1808
|
+
});
|
|
1809
|
+
_a.label = 2;
|
|
1810
|
+
case 2:
|
|
1811
|
+
if (isPrettifyed) {
|
|
1812
|
+
promptbookString = prettifyMarkdown(promptbookString);
|
|
1813
|
+
}
|
|
1814
|
+
return [2 /*return*/, promptbookString];
|
|
1815
|
+
}
|
|
1775
1816
|
});
|
|
1776
|
-
}
|
|
1777
|
-
if (isPrettifyed) {
|
|
1778
|
-
promptbookString = prettifyMarkdown(promptbookString);
|
|
1779
|
-
}
|
|
1780
|
-
return promptbookString;
|
|
1817
|
+
});
|
|
1781
1818
|
}
|
|
1782
1819
|
/**
|
|
1783
1820
|
* TODO: Maybe use some Mermaid library instead of string templating
|
|
@@ -1815,33 +1852,35 @@
|
|
|
1815
1852
|
filePaths = _c.sent();
|
|
1816
1853
|
_c.label = 2;
|
|
1817
1854
|
case 2:
|
|
1818
|
-
_c.trys.push([2,
|
|
1855
|
+
_c.trys.push([2, 11, 12, 13]);
|
|
1819
1856
|
filePaths_1 = __values(filePaths), filePaths_1_1 = filePaths_1.next();
|
|
1820
1857
|
_c.label = 3;
|
|
1821
1858
|
case 3:
|
|
1822
|
-
if (!!filePaths_1_1.done) return [3 /*break*/,
|
|
1859
|
+
if (!!filePaths_1_1.done) return [3 /*break*/, 10];
|
|
1823
1860
|
filePath = filePaths_1_1.value;
|
|
1824
1861
|
if (!filePath.endsWith('.ptbk.md')) {
|
|
1825
1862
|
console.warn(colors__default["default"].yellow("Skipping prettify of non-promptbook ".concat(filePath)));
|
|
1826
|
-
return [3 /*break*/,
|
|
1863
|
+
return [3 /*break*/, 9];
|
|
1827
1864
|
}
|
|
1828
1865
|
return [4 /*yield*/, promises.readFile(filePath, 'utf-8')];
|
|
1829
1866
|
case 4:
|
|
1830
1867
|
promptbookMarkdown = (_c.sent());
|
|
1831
1868
|
_c.label = 5;
|
|
1832
1869
|
case 5:
|
|
1833
|
-
_c.trys.push([5,
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
return [4 /*yield*/, promises.writeFile(filePath, promptbookMarkdown)];
|
|
1870
|
+
_c.trys.push([5, 8, , 9]);
|
|
1871
|
+
return [4 /*yield*/, prettifyPromptbookString(promptbookMarkdown, {
|
|
1872
|
+
isGraphAdded: true,
|
|
1873
|
+
isPrettifyed: true,
|
|
1874
|
+
// <- [🕌]
|
|
1875
|
+
})];
|
|
1840
1876
|
case 6:
|
|
1877
|
+
promptbookMarkdown = _c.sent();
|
|
1878
|
+
return [4 /*yield*/, promises.writeFile(filePath, promptbookMarkdown)];
|
|
1879
|
+
case 7:
|
|
1841
1880
|
_c.sent();
|
|
1842
1881
|
console.info(colors__default["default"].green("Prettify ".concat(filePath)));
|
|
1843
|
-
return [3 /*break*/,
|
|
1844
|
-
case
|
|
1882
|
+
return [3 /*break*/, 9];
|
|
1883
|
+
case 8:
|
|
1845
1884
|
error_1 = _c.sent();
|
|
1846
1885
|
if (!(error_1 instanceof Error)) {
|
|
1847
1886
|
throw error_1;
|
|
@@ -1850,22 +1889,22 @@
|
|
|
1850
1889
|
console.error(colors__default["default"].bgRed(error_1.name));
|
|
1851
1890
|
console.error(error_1);
|
|
1852
1891
|
process.exit(1);
|
|
1853
|
-
return [3 /*break*/,
|
|
1854
|
-
case
|
|
1892
|
+
return [3 /*break*/, 9];
|
|
1893
|
+
case 9:
|
|
1855
1894
|
filePaths_1_1 = filePaths_1.next();
|
|
1856
1895
|
return [3 /*break*/, 3];
|
|
1857
|
-
case
|
|
1858
|
-
case
|
|
1896
|
+
case 10: return [3 /*break*/, 13];
|
|
1897
|
+
case 11:
|
|
1859
1898
|
e_1_1 = _c.sent();
|
|
1860
1899
|
e_1 = { error: e_1_1 };
|
|
1861
|
-
return [3 /*break*/,
|
|
1862
|
-
case
|
|
1900
|
+
return [3 /*break*/, 13];
|
|
1901
|
+
case 12:
|
|
1863
1902
|
try {
|
|
1864
1903
|
if (filePaths_1_1 && !filePaths_1_1.done && (_b = filePaths_1.return)) _b.call(filePaths_1);
|
|
1865
1904
|
}
|
|
1866
1905
|
finally { if (e_1) throw e_1.error; }
|
|
1867
1906
|
return [7 /*endfinally*/];
|
|
1868
|
-
case
|
|
1907
|
+
case 13:
|
|
1869
1908
|
process.exit(0);
|
|
1870
1909
|
return [2 /*return*/];
|
|
1871
1910
|
}
|