@promptbook/utils 0.52.0 → 0.53.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/esm/index.es.js +727 -729
- package/esm/index.es.js.map +1 -1
- package/esm/typings/conversion/prettify/prettifyPromptbookString.d.ts +1 -1
- package/esm/typings/conversion/prettify/renderPromptbookMermaid.d.ts +2 -1
- package/esm/typings/conversion/utils/extractParametersFromPromptTemplate.d.ts +3 -3
- package/esm/typings/conversion/utils/extractVariables.d.ts +2 -1
- package/esm/typings/conversion/validation/_importPromptbook.d.ts +2 -2
- package/esm/typings/execution/LlmExecutionTools.d.ts +4 -2
- package/esm/typings/execution/PromptResult.d.ts +5 -1
- package/esm/typings/execution/ScriptExecutionTools.d.ts +2 -1
- package/esm/typings/execution/UserInterfaceTools.d.ts +2 -1
- package/esm/typings/execution/createPromptbookExecutor.d.ts +3 -3
- package/esm/typings/execution/plugins/llm-execution-tools/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +4 -2
- package/esm/typings/execution/plugins/llm-execution-tools/anthropic-claude/anthropic-claude-models.d.ts +1 -1
- package/esm/typings/execution/plugins/llm-execution-tools/azure-openai/AzureOpenAiExecutionTools.d.ts +4 -2
- package/esm/typings/execution/plugins/llm-execution-tools/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +2 -1
- package/esm/typings/execution/plugins/llm-execution-tools/mocked/MockedEchoLlmExecutionTools.d.ts +4 -2
- package/esm/typings/execution/plugins/llm-execution-tools/mocked/MockedFackedLlmExecutionTools.d.ts +4 -2
- package/esm/typings/execution/plugins/llm-execution-tools/mocked/fakeTextToExpectations.d.ts +1 -1
- package/esm/typings/execution/plugins/llm-execution-tools/multiple/MultipleLlmExecutionTools.d.ts +4 -2
- package/esm/typings/execution/plugins/llm-execution-tools/multiple/MultipleLlmExecutionToolsOptions.d.ts +2 -1
- package/esm/typings/execution/plugins/llm-execution-tools/openai/OpenAiExecutionTools.d.ts +4 -2
- package/esm/typings/execution/plugins/llm-execution-tools/openai/OpenAiExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/execution/plugins/llm-execution-tools/openai/openai-models.d.ts +1 -1
- package/esm/typings/execution/plugins/llm-execution-tools/remote/RemoteLlmExecutionTools.d.ts +4 -2
- package/esm/typings/execution/plugins/llm-execution-tools/remote/RemoteLlmExecutionToolsOptions.d.ts +2 -1
- package/esm/typings/execution/plugins/llm-execution-tools/remote/interfaces/Promptbook_Server_Progress.d.ts +1 -1
- package/esm/typings/execution/plugins/llm-execution-tools/remote/interfaces/Promptbook_Server_Response.d.ts +1 -1
- package/esm/typings/execution/plugins/llm-execution-tools/remote/interfaces/RemoteServerOptions.d.ts +2 -1
- package/esm/typings/execution/plugins/llm-execution-tools/remote/startRemoteServer.d.ts +1 -1
- package/esm/typings/execution/plugins/script-execution-tools/python/PythonExecutionTools.d.ts +3 -2
- package/esm/typings/execution/plugins/script-execution-tools/typescript/TypescriptExecutionTools.d.ts +3 -2
- package/esm/typings/execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceTools.d.ts +3 -2
- package/esm/typings/execution/plugins/user-interface-execution-tools/simple-prompt/SimplePromptInterfaceTools.d.ts +3 -2
- package/esm/typings/execution/translation/automatic-translate/automatic-translators/DebugAutomaticTranslator.d.ts +1 -1
- package/esm/typings/execution/translation/automatic-translate/automatic-translators/FakeAutomaticTranslator.d.ts +1 -1
- package/esm/typings/execution/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +2 -2
- package/esm/typings/execution/translation/automatic-translate/translateMessages.d.ts +2 -2
- package/esm/typings/execution/utils/replaceParameters.d.ts +2 -2
- package/esm/typings/library/SimplePromptbookLibrary.d.ts +1 -1
- package/esm/typings/library/constructors/createPromptbookLibraryFromDirectory.d.ts +2 -2
- package/esm/typings/library/constructors/createPromptbookLibraryFromPromise.d.ts +2 -2
- package/esm/typings/library/constructors/createPromptbookLibraryFromSources.d.ts +2 -1
- package/esm/typings/library/constructors/createPromptbookLibraryFromUrl.d.ts +2 -2
- package/esm/typings/library/constructors/createPromptbookSublibrary.d.ts +1 -1
- package/esm/typings/types/Command.d.ts +5 -2
- package/esm/typings/types/Prompt.d.ts +4 -1
- package/esm/typings/types/PromptbookJson/PromptTemplateJson.d.ts +8 -1
- package/esm/typings/types/PromptbookJson/PromptbookJson.d.ts +2 -1
- package/esm/typings/types/TaskProgress.d.ts +2 -1
- package/esm/typings/types/execution-report/ExecutionReportJson.d.ts +2 -1
- package/esm/typings/types/execution-report/countWorkingDuration.d.ts +1 -1
- package/esm/typings/utils/emojis.d.ts +1 -1
- package/esm/typings/utils/expectation-counters/index.d.ts +2 -1
- package/esm/typings/utils/extractParameters.d.ts +2 -1
- package/esm/typings/utils/markdown/addAutoGeneratedSection.d.ts +2 -1
- package/esm/typings/utils/markdown/createMarkdownChart.d.ts +2 -2
- package/esm/typings/utils/markdown/createMarkdownTable.d.ts +2 -1
- package/esm/typings/utils/markdown/escapeMarkdownBlock.d.ts +1 -1
- package/esm/typings/utils/markdown/extractAllListItemsFromMarkdown.d.ts +2 -1
- package/esm/typings/utils/markdown/extractOneBlockFromMarkdown.d.ts +2 -2
- package/esm/typings/utils/markdown/removeContentComments.d.ts +2 -1
- package/esm/typings/utils/markdown/removeMarkdownFormatting.d.ts +1 -1
- package/esm/typings/utils/markdown-json/countMarkdownStructureDeepness.d.ts +1 -1
- package/esm/typings/utils/markdown-json/markdownToMarkdownStructure.d.ts +1 -1
- package/esm/typings/utils/normalization/isValidKeyword.d.ts +1 -1
- package/esm/typings/utils/normalization/parseKeywords.d.ts +1 -1
- package/esm/typings/utils/normalization/parseKeywordsFromString.d.ts +1 -1
- package/esm/typings/utils/normalization/searchKeywords.d.ts +1 -1
- package/esm/typings/utils/postprocessing/extractBlock.d.ts +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +727 -729
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/conversion/prettify/prettifyPromptbookString.d.ts +1 -1
- package/umd/typings/conversion/prettify/renderPromptbookMermaid.d.ts +2 -1
- package/umd/typings/conversion/utils/extractParametersFromPromptTemplate.d.ts +3 -3
- package/umd/typings/conversion/utils/extractVariables.d.ts +2 -1
- package/umd/typings/conversion/validation/_importPromptbook.d.ts +2 -2
- package/umd/typings/execution/LlmExecutionTools.d.ts +4 -2
- package/umd/typings/execution/PromptResult.d.ts +5 -1
- package/umd/typings/execution/ScriptExecutionTools.d.ts +2 -1
- package/umd/typings/execution/UserInterfaceTools.d.ts +2 -1
- package/umd/typings/execution/createPromptbookExecutor.d.ts +3 -3
- package/umd/typings/execution/plugins/llm-execution-tools/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +4 -2
- package/umd/typings/execution/plugins/llm-execution-tools/anthropic-claude/anthropic-claude-models.d.ts +1 -1
- package/umd/typings/execution/plugins/llm-execution-tools/azure-openai/AzureOpenAiExecutionTools.d.ts +4 -2
- package/umd/typings/execution/plugins/llm-execution-tools/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +2 -1
- package/umd/typings/execution/plugins/llm-execution-tools/mocked/MockedEchoLlmExecutionTools.d.ts +4 -2
- package/umd/typings/execution/plugins/llm-execution-tools/mocked/MockedFackedLlmExecutionTools.d.ts +4 -2
- package/umd/typings/execution/plugins/llm-execution-tools/mocked/fakeTextToExpectations.d.ts +1 -1
- package/umd/typings/execution/plugins/llm-execution-tools/multiple/MultipleLlmExecutionTools.d.ts +4 -2
- package/umd/typings/execution/plugins/llm-execution-tools/multiple/MultipleLlmExecutionToolsOptions.d.ts +2 -1
- package/umd/typings/execution/plugins/llm-execution-tools/openai/OpenAiExecutionTools.d.ts +4 -2
- package/umd/typings/execution/plugins/llm-execution-tools/openai/OpenAiExecutionToolsOptions.d.ts +1 -1
- package/umd/typings/execution/plugins/llm-execution-tools/openai/openai-models.d.ts +1 -1
- package/umd/typings/execution/plugins/llm-execution-tools/remote/RemoteLlmExecutionTools.d.ts +4 -2
- package/umd/typings/execution/plugins/llm-execution-tools/remote/RemoteLlmExecutionToolsOptions.d.ts +2 -1
- package/umd/typings/execution/plugins/llm-execution-tools/remote/interfaces/Promptbook_Server_Progress.d.ts +1 -1
- package/umd/typings/execution/plugins/llm-execution-tools/remote/interfaces/Promptbook_Server_Response.d.ts +1 -1
- package/umd/typings/execution/plugins/llm-execution-tools/remote/interfaces/RemoteServerOptions.d.ts +2 -1
- package/umd/typings/execution/plugins/llm-execution-tools/remote/startRemoteServer.d.ts +1 -1
- package/umd/typings/execution/plugins/script-execution-tools/python/PythonExecutionTools.d.ts +3 -2
- package/umd/typings/execution/plugins/script-execution-tools/typescript/TypescriptExecutionTools.d.ts +3 -2
- package/umd/typings/execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceTools.d.ts +3 -2
- package/umd/typings/execution/plugins/user-interface-execution-tools/simple-prompt/SimplePromptInterfaceTools.d.ts +3 -2
- package/umd/typings/execution/translation/automatic-translate/automatic-translators/DebugAutomaticTranslator.d.ts +1 -1
- package/umd/typings/execution/translation/automatic-translate/automatic-translators/FakeAutomaticTranslator.d.ts +1 -1
- package/umd/typings/execution/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +2 -2
- package/umd/typings/execution/translation/automatic-translate/translateMessages.d.ts +2 -2
- package/umd/typings/execution/utils/replaceParameters.d.ts +2 -2
- package/umd/typings/library/SimplePromptbookLibrary.d.ts +1 -1
- package/umd/typings/library/constructors/createPromptbookLibraryFromDirectory.d.ts +2 -2
- package/umd/typings/library/constructors/createPromptbookLibraryFromPromise.d.ts +2 -2
- package/umd/typings/library/constructors/createPromptbookLibraryFromSources.d.ts +2 -1
- package/umd/typings/library/constructors/createPromptbookLibraryFromUrl.d.ts +2 -2
- package/umd/typings/library/constructors/createPromptbookSublibrary.d.ts +1 -1
- package/umd/typings/types/Command.d.ts +5 -2
- package/umd/typings/types/Prompt.d.ts +4 -1
- package/umd/typings/types/PromptbookJson/PromptTemplateJson.d.ts +8 -1
- package/umd/typings/types/PromptbookJson/PromptbookJson.d.ts +2 -1
- package/umd/typings/types/TaskProgress.d.ts +2 -1
- package/umd/typings/types/execution-report/ExecutionReportJson.d.ts +2 -1
- package/umd/typings/types/execution-report/countWorkingDuration.d.ts +1 -1
- package/umd/typings/utils/emojis.d.ts +1 -1
- package/umd/typings/utils/expectation-counters/index.d.ts +2 -1
- package/umd/typings/utils/extractParameters.d.ts +2 -1
- package/umd/typings/utils/markdown/addAutoGeneratedSection.d.ts +2 -1
- package/umd/typings/utils/markdown/createMarkdownChart.d.ts +2 -2
- package/umd/typings/utils/markdown/createMarkdownTable.d.ts +2 -1
- package/umd/typings/utils/markdown/escapeMarkdownBlock.d.ts +1 -1
- package/umd/typings/utils/markdown/extractAllListItemsFromMarkdown.d.ts +2 -1
- package/umd/typings/utils/markdown/extractOneBlockFromMarkdown.d.ts +2 -2
- package/umd/typings/utils/markdown/removeContentComments.d.ts +2 -1
- package/umd/typings/utils/markdown/removeMarkdownFormatting.d.ts +1 -1
- package/umd/typings/utils/markdown-json/countMarkdownStructureDeepness.d.ts +1 -1
- package/umd/typings/utils/markdown-json/markdownToMarkdownStructure.d.ts +1 -1
- package/umd/typings/utils/normalization/isValidKeyword.d.ts +1 -1
- package/umd/typings/utils/normalization/parseKeywords.d.ts +1 -1
- package/umd/typings/utils/normalization/parseKeywordsFromString.d.ts +1 -1
- package/umd/typings/utils/normalization/searchKeywords.d.ts +1 -1
- package/umd/typings/utils/postprocessing/extractBlock.d.ts +1 -1
package/umd/index.umd.js
CHANGED
|
@@ -123,242 +123,604 @@
|
|
|
123
123
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
*/
|
|
129
|
-
var UnexpectedError = /** @class */ (function (_super) {
|
|
130
|
-
__extends(UnexpectedError, _super);
|
|
131
|
-
function UnexpectedError(message) {
|
|
132
|
-
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;
|
|
133
|
-
_this.name = 'UnexpectedError';
|
|
134
|
-
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
135
|
-
return _this;
|
|
136
|
-
}
|
|
137
|
-
return UnexpectedError;
|
|
138
|
-
}(Error));
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Removes emojis from a string and fix whitespaces
|
|
142
|
-
*
|
|
143
|
-
* @param text with emojis
|
|
144
|
-
* @returns text without emojis
|
|
145
|
-
*/
|
|
146
|
-
function removeEmojis(text) {
|
|
147
|
-
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
148
|
-
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
|
149
|
-
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
|
150
|
-
text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
|
|
151
|
-
text = text.replace(/\p{Extended_Pictographic}/gu, '');
|
|
152
|
-
return text;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Function normalizes title to name which can be used as identifier
|
|
157
|
-
*/
|
|
158
|
-
function titleToName(value) {
|
|
159
|
-
value = removeEmojis(value);
|
|
160
|
-
value = normalizeToKebabCase(value);
|
|
161
|
-
// TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
|
|
162
|
-
return value;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Creates a Mermaid graph based on the promptbook
|
|
167
|
-
*
|
|
168
|
-
* Note: The result is not wrapped in a Markdown code block
|
|
169
|
-
*/
|
|
170
|
-
function renderPromptbookMermaid(promptbookJson, options) {
|
|
171
|
-
var _a = (options || {}).linkPromptTemplate, linkPromptTemplate = _a === void 0 ? function () { return null; } : _a;
|
|
172
|
-
var parameterNameToTemplateName = function (parameterName) {
|
|
173
|
-
var parameter = promptbookJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
|
|
174
|
-
if (!parameter) {
|
|
175
|
-
throw new UnexpectedError("Could not find {".concat(parameterName, "}"));
|
|
176
|
-
}
|
|
177
|
-
if (parameter.isInput) {
|
|
178
|
-
return 'input';
|
|
179
|
-
}
|
|
180
|
-
var template = promptbookJson.promptTemplates.find(function (template) { return template.resultingParameterName === parameterName; });
|
|
181
|
-
if (!template) {
|
|
182
|
-
throw new Error("Could not find template for {".concat(parameterName, "}"));
|
|
183
|
-
}
|
|
184
|
-
return normalizeTo_camelCase('template-' + titleToName(template.title));
|
|
185
|
-
};
|
|
186
|
-
var promptbookMermaid = 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.title, "\"\n\n direction TB\n\n input((Input)):::input\n ").concat(block(promptbookJson.promptTemplates
|
|
187
|
-
.flatMap(function (_a) {
|
|
188
|
-
var title = _a.title, dependentParameterNames = _a.dependentParameterNames, resultingParameterName = _a.resultingParameterName;
|
|
189
|
-
return __spreadArray([
|
|
190
|
-
"".concat(parameterNameToTemplateName(resultingParameterName), "(\"").concat(title, "\")")
|
|
191
|
-
], __read(dependentParameterNames.map(function (dependentParameterName) {
|
|
192
|
-
return "".concat(parameterNameToTemplateName(dependentParameterName), "--\"{").concat(dependentParameterName, "}\"-->").concat(parameterNameToTemplateName(resultingParameterName));
|
|
193
|
-
})), false);
|
|
194
|
-
})
|
|
195
|
-
.join('\n')), "\n\n ").concat(block(promptbookJson.parameters
|
|
196
|
-
.filter(function (_a) {
|
|
197
|
-
var isOutput = _a.isOutput;
|
|
198
|
-
return isOutput;
|
|
199
|
-
})
|
|
200
|
-
.map(function (_a) {
|
|
201
|
-
var name = _a.name;
|
|
202
|
-
return "".concat(parameterNameToTemplateName(name), "--\"{").concat(name, "}\"-->output");
|
|
203
|
-
})
|
|
204
|
-
.join('\n')), "\n output((Output)):::output\n\n ").concat(block(promptbookJson.promptTemplates
|
|
205
|
-
.map(function (promptTemplate) {
|
|
206
|
-
var link = linkPromptTemplate(promptTemplate);
|
|
207
|
-
if (link === null) {
|
|
208
|
-
return '';
|
|
209
|
-
}
|
|
210
|
-
var href = link.href, title = link.title;
|
|
211
|
-
var templateName = parameterNameToTemplateName(promptTemplate.resultingParameterName);
|
|
212
|
-
return "click ".concat(templateName, " href \"").concat(href, "\" \"").concat(title, "\";");
|
|
213
|
-
})
|
|
214
|
-
.filter(function (line) { return line !== ''; })
|
|
215
|
-
.join('\n')), "\n\n classDef input color: grey;\n classDef output color: grey;\n\n end;\n\n "); });
|
|
216
|
-
return promptbookMermaid;
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* TODO: Maybe use some Mermaid library instead of string templating
|
|
220
|
-
* TODO: [🕌] When more than 2 functionalities, split into separate functions
|
|
221
|
-
*/
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* Parses the template and returns the list of all parameter names
|
|
225
|
-
*
|
|
226
|
-
* @param template the template with parameters in {curly} braces
|
|
227
|
-
* @returns the list of parameter names
|
|
228
|
-
*/
|
|
229
|
-
function extractParameters(template) {
|
|
126
|
+
/* tslint:disable */
|
|
127
|
+
function normalizeTo_camelCase(sentence, __firstLetterCapital) {
|
|
230
128
|
var e_1, _a;
|
|
231
|
-
|
|
232
|
-
var
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
var match = matches_1_1.value;
|
|
236
|
-
var parameterName = match[0].slice(1, -1);
|
|
237
|
-
parameterNames.add(parameterName);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
241
|
-
finally {
|
|
242
|
-
try {
|
|
243
|
-
if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
|
|
244
|
-
}
|
|
245
|
-
finally { if (e_1) throw e_1.error; }
|
|
246
|
-
}
|
|
247
|
-
return parameterNames;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
252
|
-
*/
|
|
253
|
-
var PromptbookSyntaxError = /** @class */ (function (_super) {
|
|
254
|
-
__extends(PromptbookSyntaxError, _super);
|
|
255
|
-
function PromptbookSyntaxError(message) {
|
|
256
|
-
var _this = _super.call(this, message) || this;
|
|
257
|
-
_this.name = 'PromptbookSyntaxError';
|
|
258
|
-
Object.setPrototypeOf(_this, PromptbookSyntaxError.prototype);
|
|
259
|
-
return _this;
|
|
260
|
-
}
|
|
261
|
-
return PromptbookSyntaxError;
|
|
262
|
-
}(Error));
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
266
|
-
*
|
|
267
|
-
* @param script from which to extract the variables
|
|
268
|
-
* @returns the list of variable names
|
|
269
|
-
* @throws {PromptbookSyntaxError} if the script is invalid
|
|
270
|
-
*/
|
|
271
|
-
function extractVariables(script) {
|
|
272
|
-
var variables = new Set();
|
|
273
|
-
script = "(()=>{".concat(script, "})()");
|
|
129
|
+
if (__firstLetterCapital === void 0) { __firstLetterCapital = false; }
|
|
130
|
+
var charType;
|
|
131
|
+
var lastCharType = null;
|
|
132
|
+
var normalizedName = '';
|
|
274
133
|
try {
|
|
275
|
-
for (var
|
|
276
|
-
|
|
277
|
-
|
|
134
|
+
for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
|
|
135
|
+
var char = sentence_1_1.value;
|
|
136
|
+
var normalizedChar = void 0;
|
|
137
|
+
if (/^[a-z]$/.test(char)) {
|
|
138
|
+
charType = 'LOWERCASE';
|
|
139
|
+
normalizedChar = char;
|
|
278
140
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
if (
|
|
293
|
-
|
|
294
|
-
}
|
|
295
|
-
else {
|
|
296
|
-
variables.add(undefinedName);
|
|
297
|
-
script = "const ".concat(undefinedName, " = '';") + script;
|
|
141
|
+
else if (/^[A-Z]$/.test(char)) {
|
|
142
|
+
charType = 'UPPERCASE';
|
|
143
|
+
normalizedChar = char.toLowerCase();
|
|
144
|
+
}
|
|
145
|
+
else if (/^[0-9]$/.test(char)) {
|
|
146
|
+
charType = 'NUMBER';
|
|
147
|
+
normalizedChar = char;
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
charType = 'OTHER';
|
|
151
|
+
normalizedChar = '';
|
|
152
|
+
}
|
|
153
|
+
if (!lastCharType) {
|
|
154
|
+
if (__firstLetterCapital) {
|
|
155
|
+
normalizedChar = normalizedChar.toUpperCase(); //TODO: DRY
|
|
298
156
|
}
|
|
299
157
|
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
}
|
|
309
|
-
/**
|
|
310
|
-
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
311
|
-
*/
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* Parses the prompt template and returns the set of all used parameters
|
|
315
|
-
*
|
|
316
|
-
* @param promptTemplate the template with used parameters
|
|
317
|
-
* @returns the set of parameter names
|
|
318
|
-
* @throws {PromptbookSyntaxError} if the script is invalid
|
|
319
|
-
*/
|
|
320
|
-
function extractParametersFromPromptTemplate(promptTemplate) {
|
|
321
|
-
var e_1, _a, e_2, _b;
|
|
322
|
-
var parameterNames = new Set();
|
|
323
|
-
try {
|
|
324
|
-
for (var _c = __values(__spreadArray(__spreadArray(__spreadArray([], __read(extractParameters(promptTemplate.title)), false), __read(extractParameters(promptTemplate.description || '')), false), __read(extractParameters(promptTemplate.content)), false)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
325
|
-
var parameterName = _d.value;
|
|
326
|
-
parameterNames.add(parameterName);
|
|
158
|
+
else if (charType !== lastCharType &&
|
|
159
|
+
!(charType === 'LOWERCASE' && lastCharType === 'UPPERCASE') &&
|
|
160
|
+
!(lastCharType === 'NUMBER') &&
|
|
161
|
+
!(charType === 'NUMBER')) {
|
|
162
|
+
normalizedChar = normalizedChar.toUpperCase(); //TODO: [🌺] DRY
|
|
163
|
+
}
|
|
164
|
+
normalizedName += normalizedChar;
|
|
165
|
+
lastCharType = charType;
|
|
327
166
|
}
|
|
328
167
|
}
|
|
329
168
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
330
169
|
finally {
|
|
331
170
|
try {
|
|
332
|
-
if (
|
|
171
|
+
if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
|
|
333
172
|
}
|
|
334
173
|
finally { if (e_1) throw e_1.error; }
|
|
335
174
|
}
|
|
336
|
-
|
|
337
|
-
try {
|
|
338
|
-
for (var _e = __values(extractVariables(promptTemplate.content)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
339
|
-
var parameterName = _f.value;
|
|
340
|
-
parameterNames.add(parameterName);
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
344
|
-
finally {
|
|
345
|
-
try {
|
|
346
|
-
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
347
|
-
}
|
|
348
|
-
finally { if (e_2) throw e_2.error; }
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
return parameterNames;
|
|
175
|
+
return normalizedName;
|
|
352
176
|
}
|
|
353
177
|
/**
|
|
354
|
-
* TODO: [
|
|
178
|
+
* TODO: [🌺] Use some intermediate util splitWords
|
|
355
179
|
*/
|
|
356
180
|
|
|
357
181
|
/**
|
|
358
|
-
*
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
182
|
+
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
183
|
+
*/
|
|
184
|
+
var UnexpectedError = /** @class */ (function (_super) {
|
|
185
|
+
__extends(UnexpectedError, _super);
|
|
186
|
+
function UnexpectedError(message) {
|
|
187
|
+
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;
|
|
188
|
+
_this.name = 'UnexpectedError';
|
|
189
|
+
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
190
|
+
return _this;
|
|
191
|
+
}
|
|
192
|
+
return UnexpectedError;
|
|
193
|
+
}(Error));
|
|
194
|
+
|
|
195
|
+
var defaultDiacriticsRemovalMap = [
|
|
196
|
+
{
|
|
197
|
+
base: 'A',
|
|
198
|
+
letters: '\u0041\u24B6\uFF21\u00C0\u00C1\u00C2\u1EA6\u1EA4\u1EAA\u1EA8\u00C3\u0100\u0102\u1EB0\u1EAE\u1EB4\u1EB2\u0226\u01E0\u00C4\u01DE\u1EA2\u00C5\u01FA\u01CD\u0200\u0202\u1EA0\u1EAC\u1EB6\u1E00\u0104\u023A\u2C6F',
|
|
199
|
+
},
|
|
200
|
+
{ base: 'AA', letters: '\uA732' },
|
|
201
|
+
{ base: 'AE', letters: '\u00C6\u01FC\u01E2' },
|
|
202
|
+
{ base: 'AO', letters: '\uA734' },
|
|
203
|
+
{ base: 'AU', letters: '\uA736' },
|
|
204
|
+
{ base: 'AV', letters: '\uA738\uA73A' },
|
|
205
|
+
{ base: 'AY', letters: '\uA73C' },
|
|
206
|
+
{
|
|
207
|
+
base: 'B',
|
|
208
|
+
letters: '\u0042\u24B7\uFF22\u1E02\u1E04\u1E06\u0243\u0182\u0181',
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
base: 'C',
|
|
212
|
+
letters: '\u0043\u24B8\uFF23\u0106\u0108\u010A\u010C\u00C7\u1E08\u0187\u023B\uA73E',
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
base: 'D',
|
|
216
|
+
letters: '\u0044\u24B9\uFF24\u1E0A\u010E\u1E0C\u1E10\u1E12\u1E0E\u0110\u018B\u018A\u0189\uA779\u00D0',
|
|
217
|
+
},
|
|
218
|
+
{ base: 'DZ', letters: '\u01F1\u01C4' },
|
|
219
|
+
{ base: 'Dz', letters: '\u01F2\u01C5' },
|
|
220
|
+
{
|
|
221
|
+
base: 'E',
|
|
222
|
+
letters: '\u0045\u24BA\uFF25\u00C8\u00C9\u00CA\u1EC0\u1EBE\u1EC4\u1EC2\u1EBC\u0112\u1E14\u1E16\u0114\u0116\u00CB\u1EBA\u011A\u0204\u0206\u1EB8\u1EC6\u0228\u1E1C\u0118\u1E18\u1E1A\u0190\u018E',
|
|
223
|
+
},
|
|
224
|
+
{ base: 'F', letters: '\u0046\u24BB\uFF26\u1E1E\u0191\uA77B' },
|
|
225
|
+
{
|
|
226
|
+
base: 'G',
|
|
227
|
+
letters: '\u0047\u24BC\uFF27\u01F4\u011C\u1E20\u011E\u0120\u01E6\u0122\u01E4\u0193\uA7A0\uA77D\uA77E',
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
base: 'H',
|
|
231
|
+
letters: '\u0048\u24BD\uFF28\u0124\u1E22\u1E26\u021E\u1E24\u1E28\u1E2A\u0126\u2C67\u2C75\uA78D',
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
base: 'I',
|
|
235
|
+
letters: '\u0049\u24BE\uFF29\u00CC\u00CD\u00CE\u0128\u012A\u012C\u0130\u00CF\u1E2E\u1EC8\u01CF\u0208\u020A\u1ECA\u012E\u1E2C\u0197',
|
|
236
|
+
},
|
|
237
|
+
{ base: 'J', letters: '\u004A\u24BF\uFF2A\u0134\u0248' },
|
|
238
|
+
{
|
|
239
|
+
base: 'K',
|
|
240
|
+
letters: '\u004B\u24C0\uFF2B\u1E30\u01E8\u1E32\u0136\u1E34\u0198\u2C69\uA740\uA742\uA744\uA7A2',
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
base: 'L',
|
|
244
|
+
letters: '\u004C\u24C1\uFF2C\u013F\u0139\u013D\u1E36\u1E38\u013B\u1E3C\u1E3A\u0141\u023D\u2C62\u2C60\uA748\uA746\uA780',
|
|
245
|
+
},
|
|
246
|
+
{ base: 'LJ', letters: '\u01C7' },
|
|
247
|
+
{ base: 'Lj', letters: '\u01C8' },
|
|
248
|
+
{ base: 'M', letters: '\u004D\u24C2\uFF2D\u1E3E\u1E40\u1E42\u2C6E\u019C' },
|
|
249
|
+
{
|
|
250
|
+
base: 'N',
|
|
251
|
+
letters: '\u004E\u24C3\uFF2E\u01F8\u0143\u00D1\u1E44\u0147\u1E46\u0145\u1E4A\u1E48\u0220\u019D\uA790\uA7A4',
|
|
252
|
+
},
|
|
253
|
+
{ base: 'NJ', letters: '\u01CA' },
|
|
254
|
+
{ base: 'Nj', letters: '\u01CB' },
|
|
255
|
+
{
|
|
256
|
+
base: 'O',
|
|
257
|
+
letters: '\u004F\u24C4\uFF2F\u00D2\u00D3\u00D4\u1ED2\u1ED0\u1ED6\u1ED4\u00D5\u1E4C\u022C\u1E4E\u014C\u1E50\u1E52\u014E\u022E\u0230\u00D6\u022A\u1ECE\u0150\u01D1\u020C\u020E\u01A0\u1EDC\u1EDA\u1EE0\u1EDE\u1EE2\u1ECC\u1ED8\u01EA\u01EC\u00D8\u01FE\u0186\u019F\uA74A\uA74C',
|
|
258
|
+
},
|
|
259
|
+
{ base: 'OI', letters: '\u01A2' },
|
|
260
|
+
{ base: 'OO', letters: '\uA74E' },
|
|
261
|
+
{ base: 'OU', letters: '\u0222' },
|
|
262
|
+
{ base: 'OE', letters: '\u008C\u0152' },
|
|
263
|
+
{ base: 'oe', letters: '\u009C\u0153' },
|
|
264
|
+
{
|
|
265
|
+
base: 'P',
|
|
266
|
+
letters: '\u0050\u24C5\uFF30\u1E54\u1E56\u01A4\u2C63\uA750\uA752\uA754',
|
|
267
|
+
},
|
|
268
|
+
{ base: 'Q', letters: '\u0051\u24C6\uFF31\uA756\uA758\u024A' },
|
|
269
|
+
{
|
|
270
|
+
base: 'R',
|
|
271
|
+
letters: '\u0052\u24C7\uFF32\u0154\u1E58\u0158\u0210\u0212\u1E5A\u1E5C\u0156\u1E5E\u024C\u2C64\uA75A\uA7A6\uA782',
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
base: 'S',
|
|
275
|
+
letters: '\u0053\u24C8\uFF33\u1E9E\u015A\u1E64\u015C\u1E60\u0160\u1E66\u1E62\u1E68\u0218\u015E\u2C7E\uA7A8\uA784',
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
base: 'T',
|
|
279
|
+
letters: '\u0054\u24C9\uFF34\u1E6A\u0164\u1E6C\u021A\u0162\u1E70\u1E6E\u0166\u01AC\u01AE\u023E\uA786',
|
|
280
|
+
},
|
|
281
|
+
{ base: 'TZ', letters: '\uA728' },
|
|
282
|
+
{
|
|
283
|
+
base: 'U',
|
|
284
|
+
letters: '\u0055\u24CA\uFF35\u00D9\u00DA\u00DB\u0168\u1E78\u016A\u1E7A\u016C\u00DC\u01DB\u01D7\u01D5\u01D9\u1EE6\u016E\u0170\u01D3\u0214\u0216\u01AF\u1EEA\u1EE8\u1EEE\u1EEC\u1EF0\u1EE4\u1E72\u0172\u1E76\u1E74\u0244',
|
|
285
|
+
},
|
|
286
|
+
{ base: 'V', letters: '\u0056\u24CB\uFF36\u1E7C\u1E7E\u01B2\uA75E\u0245' },
|
|
287
|
+
{ base: 'VY', letters: '\uA760' },
|
|
288
|
+
{
|
|
289
|
+
base: 'W',
|
|
290
|
+
letters: '\u0057\u24CC\uFF37\u1E80\u1E82\u0174\u1E86\u1E84\u1E88\u2C72',
|
|
291
|
+
},
|
|
292
|
+
{ base: 'X', letters: '\u0058\u24CD\uFF38\u1E8A\u1E8C' },
|
|
293
|
+
{
|
|
294
|
+
base: 'Y',
|
|
295
|
+
letters: '\u0059\u24CE\uFF39\u1EF2\u00DD\u0176\u1EF8\u0232\u1E8E\u0178\u1EF6\u1EF4\u01B3\u024E\u1EFE',
|
|
296
|
+
},
|
|
297
|
+
{
|
|
298
|
+
base: 'Z',
|
|
299
|
+
letters: '\u005A\u24CF\uFF3A\u0179\u1E90\u017B\u017D\u1E92\u1E94\u01B5\u0224\u2C7F\u2C6B\uA762',
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
base: 'a',
|
|
303
|
+
letters: '\u0061\u24D0\uFF41\u1E9A\u00E0\u00E1\u00E2\u1EA7\u1EA5\u1EAB\u1EA9\u00E3\u0101\u0103\u1EB1\u1EAF\u1EB5\u1EB3\u0227\u01E1\u00E4\u01DF\u1EA3\u00E5\u01FB\u01CE\u0201\u0203\u1EA1\u1EAD\u1EB7\u1E01\u0105\u2C65\u0250',
|
|
304
|
+
},
|
|
305
|
+
{ base: 'aa', letters: '\uA733' },
|
|
306
|
+
{ base: 'ae', letters: '\u00E6\u01FD\u01E3' },
|
|
307
|
+
{ base: 'ao', letters: '\uA735' },
|
|
308
|
+
{ base: 'au', letters: '\uA737' },
|
|
309
|
+
{ base: 'av', letters: '\uA739\uA73B' },
|
|
310
|
+
{ base: 'ay', letters: '\uA73D' },
|
|
311
|
+
{
|
|
312
|
+
base: 'b',
|
|
313
|
+
letters: '\u0062\u24D1\uFF42\u1E03\u1E05\u1E07\u0180\u0183\u0253',
|
|
314
|
+
},
|
|
315
|
+
{
|
|
316
|
+
base: 'c',
|
|
317
|
+
letters: '\u0063\u24D2\uFF43\u0107\u0109\u010B\u010D\u00E7\u1E09\u0188\u023C\uA73F\u2184',
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
base: 'd',
|
|
321
|
+
letters: '\u0064\u24D3\uFF44\u1E0B\u010F\u1E0D\u1E11\u1E13\u1E0F\u0111\u018C\u0256\u0257\uA77A',
|
|
322
|
+
},
|
|
323
|
+
{ base: 'dz', letters: '\u01F3\u01C6' },
|
|
324
|
+
{
|
|
325
|
+
base: 'e',
|
|
326
|
+
letters: '\u0065\u24D4\uFF45\u00E8\u00E9\u00EA\u1EC1\u1EBF\u1EC5\u1EC3\u1EBD\u0113\u1E15\u1E17\u0115\u0117\u00EB\u1EBB\u011B\u0205\u0207\u1EB9\u1EC7\u0229\u1E1D\u0119\u1E19\u1E1B\u0247\u025B\u01DD',
|
|
327
|
+
},
|
|
328
|
+
{ base: 'f', letters: '\u0066\u24D5\uFF46\u1E1F\u0192\uA77C' },
|
|
329
|
+
{
|
|
330
|
+
base: 'g',
|
|
331
|
+
letters: '\u0067\u24D6\uFF47\u01F5\u011D\u1E21\u011F\u0121\u01E7\u0123\u01E5\u0260\uA7A1\u1D79\uA77F',
|
|
332
|
+
},
|
|
333
|
+
{
|
|
334
|
+
base: 'h',
|
|
335
|
+
letters: '\u0068\u24D7\uFF48\u0125\u1E23\u1E27\u021F\u1E25\u1E29\u1E2B\u1E96\u0127\u2C68\u2C76\u0265',
|
|
336
|
+
},
|
|
337
|
+
{ base: 'hv', letters: '\u0195' },
|
|
338
|
+
{
|
|
339
|
+
base: 'i',
|
|
340
|
+
letters: '\u0069\u24D8\uFF49\u00EC\u00ED\u00EE\u0129\u012B\u012D\u00EF\u1E2F\u1EC9\u01D0\u0209\u020B\u1ECB\u012F\u1E2D\u0268\u0131',
|
|
341
|
+
},
|
|
342
|
+
{ base: 'j', letters: '\u006A\u24D9\uFF4A\u0135\u01F0\u0249' },
|
|
343
|
+
{
|
|
344
|
+
base: 'k',
|
|
345
|
+
letters: '\u006B\u24DA\uFF4B\u1E31\u01E9\u1E33\u0137\u1E35\u0199\u2C6A\uA741\uA743\uA745\uA7A3',
|
|
346
|
+
},
|
|
347
|
+
{
|
|
348
|
+
base: 'l',
|
|
349
|
+
letters: '\u006C\u24DB\uFF4C\u0140\u013A\u013E\u1E37\u1E39\u013C\u1E3D\u1E3B\u017F\u0142\u019A\u026B\u2C61\uA749\uA781\uA747',
|
|
350
|
+
},
|
|
351
|
+
{ base: 'lj', letters: '\u01C9' },
|
|
352
|
+
{ base: 'm', letters: '\u006D\u24DC\uFF4D\u1E3F\u1E41\u1E43\u0271\u026F' },
|
|
353
|
+
{
|
|
354
|
+
base: 'n',
|
|
355
|
+
letters: '\u006E\u24DD\uFF4E\u01F9\u0144\u00F1\u1E45\u0148\u1E47\u0146\u1E4B\u1E49\u019E\u0272\u0149\uA791\uA7A5',
|
|
356
|
+
},
|
|
357
|
+
{ base: 'nj', letters: '\u01CC' },
|
|
358
|
+
{
|
|
359
|
+
base: 'o',
|
|
360
|
+
letters: '\u006F\u24DE\uFF4F\u00F2\u00F3\u00F4\u1ED3\u1ED1\u1ED7\u1ED5\u00F5\u1E4D\u022D\u1E4F\u014D\u1E51\u1E53\u014F\u022F\u0231\u00F6\u022B\u1ECF\u0151\u01D2\u020D\u020F\u01A1\u1EDD\u1EDB\u1EE1\u1EDF\u1EE3\u1ECD\u1ED9\u01EB\u01ED\u00F8\u01FF\u0254\uA74B\uA74D\u0275',
|
|
361
|
+
},
|
|
362
|
+
{ base: 'oi', letters: '\u01A3' },
|
|
363
|
+
{ base: 'ou', letters: '\u0223' },
|
|
364
|
+
{ base: 'oo', letters: '\uA74F' },
|
|
365
|
+
{
|
|
366
|
+
base: 'p',
|
|
367
|
+
letters: '\u0070\u24DF\uFF50\u1E55\u1E57\u01A5\u1D7D\uA751\uA753\uA755',
|
|
368
|
+
},
|
|
369
|
+
{ base: 'q', letters: '\u0071\u24E0\uFF51\u024B\uA757\uA759' },
|
|
370
|
+
{
|
|
371
|
+
base: 'r',
|
|
372
|
+
letters: '\u0072\u24E1\uFF52\u0155\u1E59\u0159\u0211\u0213\u1E5B\u1E5D\u0157\u1E5F\u024D\u027D\uA75B\uA7A7\uA783',
|
|
373
|
+
},
|
|
374
|
+
{
|
|
375
|
+
base: 's',
|
|
376
|
+
letters: '\u0073\u24E2\uFF53\u00DF\u015B\u1E65\u015D\u1E61\u0161\u1E67\u1E63\u1E69\u0219\u015F\u023F\uA7A9\uA785\u1E9B',
|
|
377
|
+
},
|
|
378
|
+
{
|
|
379
|
+
base: 't',
|
|
380
|
+
letters: '\u0074\u24E3\uFF54\u1E6B\u1E97\u0165\u1E6D\u021B\u0163\u1E71\u1E6F\u0167\u01AD\u0288\u2C66\uA787',
|
|
381
|
+
},
|
|
382
|
+
{ base: 'tz', letters: '\uA729' },
|
|
383
|
+
{
|
|
384
|
+
base: 'u',
|
|
385
|
+
letters: '\u0075\u24E4\uFF55\u00F9\u00FA\u00FB\u0169\u1E79\u016B\u1E7B\u016D\u00FC\u01DC\u01D8\u01D6\u01DA\u1EE7\u016F\u0171\u01D4\u0215\u0217\u01B0\u1EEB\u1EE9\u1EEF\u1EED\u1EF1\u1EE5\u1E73\u0173\u1E77\u1E75\u0289',
|
|
386
|
+
},
|
|
387
|
+
{ base: 'v', letters: '\u0076\u24E5\uFF56\u1E7D\u1E7F\u028B\uA75F\u028C' },
|
|
388
|
+
{ base: 'vy', letters: '\uA761' },
|
|
389
|
+
{
|
|
390
|
+
base: 'w',
|
|
391
|
+
letters: '\u0077\u24E6\uFF57\u1E81\u1E83\u0175\u1E87\u1E85\u1E98\u1E89\u2C73',
|
|
392
|
+
},
|
|
393
|
+
{ base: 'x', letters: '\u0078\u24E7\uFF58\u1E8B\u1E8D' },
|
|
394
|
+
{
|
|
395
|
+
base: 'y',
|
|
396
|
+
letters: '\u0079\u24E8\uFF59\u1EF3\u00FD\u0177\u1EF9\u0233\u1E8F\u00FF\u1EF7\u1E99\u1EF5\u01B4\u024F\u1EFF',
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
base: 'z',
|
|
400
|
+
letters: '\u007A\u24E9\uFF5A\u017A\u1E91\u017C\u017E\u1E93\u1E95\u01B6\u0225\u0240\u2C6C\uA763',
|
|
401
|
+
},
|
|
402
|
+
];
|
|
403
|
+
/**
|
|
404
|
+
* Map of letters from diacritic variant to diacritless variant
|
|
405
|
+
* Contains lowercase and uppercase separatelly
|
|
406
|
+
*
|
|
407
|
+
* > "á" => "a"
|
|
408
|
+
* > "ě" => "e"
|
|
409
|
+
* > "Ă" => "A"
|
|
410
|
+
* > ...
|
|
411
|
+
*/
|
|
412
|
+
var DIACRITIC_VARIANTS_LETTERS = {};
|
|
413
|
+
// tslint:disable-next-line: prefer-for-of
|
|
414
|
+
for (var i = 0; i < defaultDiacriticsRemovalMap.length; i++) {
|
|
415
|
+
var letters = defaultDiacriticsRemovalMap[i].letters;
|
|
416
|
+
// tslint:disable-next-line: prefer-for-of
|
|
417
|
+
for (var j = 0; j < letters.length; j++) {
|
|
418
|
+
DIACRITIC_VARIANTS_LETTERS[letters[j]] = defaultDiacriticsRemovalMap[i].base;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
// <- TODO: [🍓] Put to maker function to save execution time if not needed
|
|
422
|
+
/*
|
|
423
|
+
@see https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript
|
|
424
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
425
|
+
you may not use this file except in compliance with the License.
|
|
426
|
+
You may obtain a copy of the License at
|
|
427
|
+
|
|
428
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
429
|
+
|
|
430
|
+
Unless required by applicable law or agreed to in writing, software
|
|
431
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
432
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
433
|
+
See the License for the specific language governing permissions and
|
|
434
|
+
limitations under the License.
|
|
435
|
+
*/
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
*
|
|
439
|
+
*/
|
|
440
|
+
function removeDiacritics(input) {
|
|
441
|
+
/*eslint no-control-regex: "off"*/
|
|
442
|
+
return input.replace(/[^\u0000-\u007E]/g, function (a) {
|
|
443
|
+
return DIACRITIC_VARIANTS_LETTERS[a] || a;
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/* tslint:disable */
|
|
448
|
+
function normalizeToKebabCase(sentence) {
|
|
449
|
+
var e_1, _a;
|
|
450
|
+
sentence = removeDiacritics(sentence);
|
|
451
|
+
var charType;
|
|
452
|
+
var lastCharType = 'OTHER';
|
|
453
|
+
var normalizedName = '';
|
|
454
|
+
try {
|
|
455
|
+
for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
|
|
456
|
+
var char = sentence_1_1.value;
|
|
457
|
+
var normalizedChar = void 0;
|
|
458
|
+
if (/^[a-z]$/.test(char)) {
|
|
459
|
+
charType = 'LOWERCASE';
|
|
460
|
+
normalizedChar = char;
|
|
461
|
+
}
|
|
462
|
+
else if (/^[A-Z]$/.test(char)) {
|
|
463
|
+
charType = 'UPPERCASE';
|
|
464
|
+
normalizedChar = char.toLowerCase();
|
|
465
|
+
}
|
|
466
|
+
else if (/^[0-9]$/.test(char)) {
|
|
467
|
+
charType = 'NUMBER';
|
|
468
|
+
normalizedChar = char;
|
|
469
|
+
}
|
|
470
|
+
else if (/^\/$/.test(char)) {
|
|
471
|
+
charType = 'SLASH';
|
|
472
|
+
normalizedChar = char;
|
|
473
|
+
}
|
|
474
|
+
else {
|
|
475
|
+
charType = 'OTHER';
|
|
476
|
+
normalizedChar = '-';
|
|
477
|
+
}
|
|
478
|
+
if (charType !== lastCharType &&
|
|
479
|
+
!(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
|
|
480
|
+
!(lastCharType === 'NUMBER') &&
|
|
481
|
+
!(charType === 'NUMBER')) {
|
|
482
|
+
normalizedName += '-';
|
|
483
|
+
}
|
|
484
|
+
normalizedName += normalizedChar;
|
|
485
|
+
lastCharType = charType;
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
489
|
+
finally {
|
|
490
|
+
try {
|
|
491
|
+
if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
|
|
492
|
+
}
|
|
493
|
+
finally { if (e_1) throw e_1.error; }
|
|
494
|
+
}
|
|
495
|
+
normalizedName = normalizedName.split(/-+/g).join('-');
|
|
496
|
+
normalizedName = normalizedName.split(/-?\/-?/g).join('/');
|
|
497
|
+
normalizedName = normalizedName.replace(/^-/, '');
|
|
498
|
+
normalizedName = normalizedName.replace(/-$/, '');
|
|
499
|
+
return normalizedName;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* Removes emojis from a string and fix whitespaces
|
|
504
|
+
*
|
|
505
|
+
* @param text with emojis
|
|
506
|
+
* @returns text without emojis
|
|
507
|
+
*/
|
|
508
|
+
function removeEmojis(text) {
|
|
509
|
+
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
510
|
+
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
|
511
|
+
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
|
512
|
+
text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
|
|
513
|
+
text = text.replace(/\p{Extended_Pictographic}/gu, '');
|
|
514
|
+
return text;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* Function normalizes title to name which can be used as identifier
|
|
519
|
+
*/
|
|
520
|
+
function titleToName(value) {
|
|
521
|
+
value = removeEmojis(value);
|
|
522
|
+
value = normalizeToKebabCase(value);
|
|
523
|
+
// TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
|
|
524
|
+
return value;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* Creates a Mermaid graph based on the promptbook
|
|
529
|
+
*
|
|
530
|
+
* Note: The result is not wrapped in a Markdown code block
|
|
531
|
+
*/
|
|
532
|
+
function renderPromptbookMermaid(promptbookJson, options) {
|
|
533
|
+
var _a = (options || {}).linkPromptTemplate, linkPromptTemplate = _a === void 0 ? function () { return null; } : _a;
|
|
534
|
+
var parameterNameToTemplateName = function (parameterName) {
|
|
535
|
+
var parameter = promptbookJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
|
|
536
|
+
if (!parameter) {
|
|
537
|
+
throw new UnexpectedError("Could not find {".concat(parameterName, "}"));
|
|
538
|
+
}
|
|
539
|
+
if (parameter.isInput) {
|
|
540
|
+
return 'input';
|
|
541
|
+
}
|
|
542
|
+
var template = promptbookJson.promptTemplates.find(function (template) { return template.resultingParameterName === parameterName; });
|
|
543
|
+
if (!template) {
|
|
544
|
+
throw new Error("Could not find template for {".concat(parameterName, "}"));
|
|
545
|
+
}
|
|
546
|
+
return normalizeTo_camelCase('template-' + titleToName(template.title));
|
|
547
|
+
};
|
|
548
|
+
var promptbookMermaid = 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.title, "\"\n\n direction TB\n\n input((Input)):::input\n ").concat(block(promptbookJson.promptTemplates
|
|
549
|
+
.flatMap(function (_a) {
|
|
550
|
+
var title = _a.title, dependentParameterNames = _a.dependentParameterNames, resultingParameterName = _a.resultingParameterName;
|
|
551
|
+
return __spreadArray([
|
|
552
|
+
"".concat(parameterNameToTemplateName(resultingParameterName), "(\"").concat(title, "\")")
|
|
553
|
+
], __read(dependentParameterNames.map(function (dependentParameterName) {
|
|
554
|
+
return "".concat(parameterNameToTemplateName(dependentParameterName), "--\"{").concat(dependentParameterName, "}\"-->").concat(parameterNameToTemplateName(resultingParameterName));
|
|
555
|
+
})), false);
|
|
556
|
+
})
|
|
557
|
+
.join('\n')), "\n\n ").concat(block(promptbookJson.parameters
|
|
558
|
+
.filter(function (_a) {
|
|
559
|
+
var isOutput = _a.isOutput;
|
|
560
|
+
return isOutput;
|
|
561
|
+
})
|
|
562
|
+
.map(function (_a) {
|
|
563
|
+
var name = _a.name;
|
|
564
|
+
return "".concat(parameterNameToTemplateName(name), "--\"{").concat(name, "}\"-->output");
|
|
565
|
+
})
|
|
566
|
+
.join('\n')), "\n output((Output)):::output\n\n ").concat(block(promptbookJson.promptTemplates
|
|
567
|
+
.map(function (promptTemplate) {
|
|
568
|
+
var link = linkPromptTemplate(promptTemplate);
|
|
569
|
+
if (link === null) {
|
|
570
|
+
return '';
|
|
571
|
+
}
|
|
572
|
+
var href = link.href, title = link.title;
|
|
573
|
+
var templateName = parameterNameToTemplateName(promptTemplate.resultingParameterName);
|
|
574
|
+
return "click ".concat(templateName, " href \"").concat(href, "\" \"").concat(title, "\";");
|
|
575
|
+
})
|
|
576
|
+
.filter(function (line) { return line !== ''; })
|
|
577
|
+
.join('\n')), "\n\n classDef input color: grey;\n classDef output color: grey;\n\n end;\n\n "); });
|
|
578
|
+
return promptbookMermaid;
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* TODO: Maybe use some Mermaid library instead of string templating
|
|
582
|
+
* TODO: [🕌] When more than 2 functionalities, split into separate functions
|
|
583
|
+
*/
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* Parses the template and returns the list of all parameter names
|
|
587
|
+
*
|
|
588
|
+
* @param template the template with parameters in {curly} braces
|
|
589
|
+
* @returns the list of parameter names
|
|
590
|
+
*/
|
|
591
|
+
function extractParameters(template) {
|
|
592
|
+
var e_1, _a;
|
|
593
|
+
var matches = template.matchAll(/{\w+}/g);
|
|
594
|
+
var parameterNames = new Set();
|
|
595
|
+
try {
|
|
596
|
+
for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
|
|
597
|
+
var match = matches_1_1.value;
|
|
598
|
+
var parameterName = match[0].slice(1, -1);
|
|
599
|
+
parameterNames.add(parameterName);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
603
|
+
finally {
|
|
604
|
+
try {
|
|
605
|
+
if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
|
|
606
|
+
}
|
|
607
|
+
finally { if (e_1) throw e_1.error; }
|
|
608
|
+
}
|
|
609
|
+
return parameterNames;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
/**
|
|
613
|
+
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
614
|
+
*/
|
|
615
|
+
var PromptbookSyntaxError = /** @class */ (function (_super) {
|
|
616
|
+
__extends(PromptbookSyntaxError, _super);
|
|
617
|
+
function PromptbookSyntaxError(message) {
|
|
618
|
+
var _this = _super.call(this, message) || this;
|
|
619
|
+
_this.name = 'PromptbookSyntaxError';
|
|
620
|
+
Object.setPrototypeOf(_this, PromptbookSyntaxError.prototype);
|
|
621
|
+
return _this;
|
|
622
|
+
}
|
|
623
|
+
return PromptbookSyntaxError;
|
|
624
|
+
}(Error));
|
|
625
|
+
|
|
626
|
+
/**
|
|
627
|
+
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
628
|
+
*
|
|
629
|
+
* @param script from which to extract the variables
|
|
630
|
+
* @returns the list of variable names
|
|
631
|
+
* @throws {PromptbookSyntaxError} if the script is invalid
|
|
632
|
+
*/
|
|
633
|
+
function extractVariables(script) {
|
|
634
|
+
var variables = new Set();
|
|
635
|
+
script = "(()=>{".concat(script, "})()");
|
|
636
|
+
try {
|
|
637
|
+
for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
|
|
638
|
+
try {
|
|
639
|
+
eval(script);
|
|
640
|
+
}
|
|
641
|
+
catch (error) {
|
|
642
|
+
if (!(error instanceof ReferenceError)) {
|
|
643
|
+
throw error;
|
|
644
|
+
}
|
|
645
|
+
var undefinedName = error.message.split(' ')[0];
|
|
646
|
+
/*
|
|
647
|
+
Note: Remapping error
|
|
648
|
+
From: [ReferenceError: thing is not defined],
|
|
649
|
+
To: [Error: Parameter {thing} is not defined],
|
|
650
|
+
*/
|
|
651
|
+
if (!undefinedName) {
|
|
652
|
+
throw error;
|
|
653
|
+
}
|
|
654
|
+
if (script.includes(undefinedName + '(')) {
|
|
655
|
+
script = "const ".concat(undefinedName, " = ()=>'';") + script;
|
|
656
|
+
}
|
|
657
|
+
else {
|
|
658
|
+
variables.add(undefinedName);
|
|
659
|
+
script = "const ".concat(undefinedName, " = '';") + script;
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
catch (error) {
|
|
664
|
+
if (!(error instanceof Error)) {
|
|
665
|
+
throw error;
|
|
666
|
+
}
|
|
667
|
+
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 "); }));
|
|
668
|
+
}
|
|
669
|
+
return variables;
|
|
670
|
+
}
|
|
671
|
+
/**
|
|
672
|
+
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
673
|
+
*/
|
|
674
|
+
|
|
675
|
+
/**
|
|
676
|
+
* Parses the prompt template and returns the set of all used parameters
|
|
677
|
+
*
|
|
678
|
+
* @param promptTemplate the template with used parameters
|
|
679
|
+
* @returns the set of parameter names
|
|
680
|
+
* @throws {PromptbookSyntaxError} if the script is invalid
|
|
681
|
+
*/
|
|
682
|
+
function extractParametersFromPromptTemplate(promptTemplate) {
|
|
683
|
+
var e_1, _a, e_2, _b;
|
|
684
|
+
var parameterNames = new Set();
|
|
685
|
+
try {
|
|
686
|
+
for (var _c = __values(__spreadArray(__spreadArray(__spreadArray([], __read(extractParameters(promptTemplate.title)), false), __read(extractParameters(promptTemplate.description || '')), false), __read(extractParameters(promptTemplate.content)), false)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
687
|
+
var parameterName = _d.value;
|
|
688
|
+
parameterNames.add(parameterName);
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
692
|
+
finally {
|
|
693
|
+
try {
|
|
694
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
695
|
+
}
|
|
696
|
+
finally { if (e_1) throw e_1.error; }
|
|
697
|
+
}
|
|
698
|
+
if (promptTemplate.executionType === 'SCRIPT') {
|
|
699
|
+
try {
|
|
700
|
+
for (var _e = __values(extractVariables(promptTemplate.content)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
701
|
+
var parameterName = _f.value;
|
|
702
|
+
parameterNames.add(parameterName);
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
706
|
+
finally {
|
|
707
|
+
try {
|
|
708
|
+
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
709
|
+
}
|
|
710
|
+
finally { if (e_2) throw e_2.error; }
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
return parameterNames;
|
|
714
|
+
}
|
|
715
|
+
/**
|
|
716
|
+
* TODO: [🔣] If script require contentLanguage
|
|
717
|
+
*/
|
|
718
|
+
|
|
719
|
+
/**
|
|
720
|
+
* Function parseNumber will parse number from string
|
|
721
|
+
*
|
|
722
|
+
* Unlike Number.parseInt, Number.parseFloat it will never ever result in NaN
|
|
723
|
+
* Note: it also works only with decimal numbers
|
|
362
724
|
*
|
|
363
725
|
* @returns parsed number
|
|
364
726
|
* @throws {PromptbookSyntaxError} if the value is not a number
|
|
@@ -535,420 +897,168 @@
|
|
|
535
897
|
_e.trys.push([1, 6, 7, 8]);
|
|
536
898
|
_b = __values(array), _c = _b.next();
|
|
537
899
|
_e.label = 2;
|
|
538
|
-
case 2:
|
|
539
|
-
if (!!_c.done) return [3 /*break*/, 5];
|
|
540
|
-
item = _c.value;
|
|
541
|
-
return [5 /*yield**/, _loop_1(item)];
|
|
542
|
-
case 3:
|
|
543
|
-
_e.sent();
|
|
544
|
-
_e.label = 4;
|
|
545
|
-
case 4:
|
|
546
|
-
_c = _b.next();
|
|
547
|
-
return [3 /*break*/, 2];
|
|
548
|
-
case 5: return [3 /*break*/, 8];
|
|
549
|
-
case 6:
|
|
550
|
-
e_1_1 = _e.sent();
|
|
551
|
-
e_1 = { error: e_1_1 };
|
|
552
|
-
return [3 /*break*/, 8];
|
|
553
|
-
case 7:
|
|
554
|
-
try {
|
|
555
|
-
if (_c && !_c.done && (_d = _b.return)) _d.call(_b);
|
|
556
|
-
}
|
|
557
|
-
finally { if (e_1) throw e_1.error; }
|
|
558
|
-
return [7 /*endfinally*/];
|
|
559
|
-
case 8: return [4 /*yield*/, Promise.all(tasks)];
|
|
560
|
-
case 9:
|
|
561
|
-
_e.sent();
|
|
562
|
-
return [2 /*return*/];
|
|
563
|
-
}
|
|
564
|
-
});
|
|
565
|
-
});
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
/**
|
|
569
|
-
* The maximum number of iterations for a loops
|
|
570
|
-
*/
|
|
571
|
-
var LOOP_LIMIT = 1000;
|
|
572
|
-
|
|
573
|
-
/**
|
|
574
|
-
* This error occurs during the parameter replacement in the template
|
|
575
|
-
*
|
|
576
|
-
* Note: This is a kindof subtype of PromptbookExecutionError because it occurs during the execution of the pipeline
|
|
577
|
-
*/
|
|
578
|
-
var TemplateError = /** @class */ (function (_super) {
|
|
579
|
-
__extends(TemplateError, _super);
|
|
580
|
-
function TemplateError(message) {
|
|
581
|
-
var _this = _super.call(this, message) || this;
|
|
582
|
-
_this.name = 'TemplateError';
|
|
583
|
-
Object.setPrototypeOf(_this, TemplateError.prototype);
|
|
584
|
-
return _this;
|
|
585
|
-
}
|
|
586
|
-
return TemplateError;
|
|
587
|
-
}(Error));
|
|
588
|
-
|
|
589
|
-
/**
|
|
590
|
-
* Replaces parameters in template with values from parameters object
|
|
591
|
-
*
|
|
592
|
-
* @param template the template with parameters in {curly} braces
|
|
593
|
-
* @param parameters the object with parameters
|
|
594
|
-
* @returns the template with replaced parameters
|
|
595
|
-
* @throws {TemplateError} if parameter is not defined, not closed, or not opened
|
|
596
|
-
*
|
|
597
|
-
* @private within the createPromptbookExecutor
|
|
598
|
-
*/
|
|
599
|
-
function replaceParameters(template, parameters) {
|
|
600
|
-
var replacedTemplate = template;
|
|
601
|
-
var match;
|
|
602
|
-
var loopLimit = LOOP_LIMIT;
|
|
603
|
-
var _loop_1 = function () {
|
|
604
|
-
if (loopLimit-- < 0) {
|
|
605
|
-
throw new UnexpectedError('Loop limit reached during parameters replacement in `replaceParameters`');
|
|
606
|
-
}
|
|
607
|
-
var precol = match.groups.precol;
|
|
608
|
-
var parameterName = match.groups.parameterName;
|
|
609
|
-
if (parameterName === '') {
|
|
610
|
-
return "continue";
|
|
611
|
-
}
|
|
612
|
-
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
|
|
613
|
-
throw new TemplateError('Parameter is already opened or not closed');
|
|
614
|
-
}
|
|
615
|
-
if (parameters[parameterName] === undefined) {
|
|
616
|
-
throw new TemplateError("Parameter {".concat(parameterName, "} is not defined"));
|
|
617
|
-
}
|
|
618
|
-
var parameterValue = parameters[parameterName];
|
|
619
|
-
if (parameterValue === undefined) {
|
|
620
|
-
throw new TemplateError("Parameter {".concat(parameterName, "} is not defined"));
|
|
621
|
-
}
|
|
622
|
-
parameterValue = parameterValue.toString();
|
|
623
|
-
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
624
|
-
parameterValue = parameterValue
|
|
625
|
-
.split('\n')
|
|
626
|
-
.map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
|
|
627
|
-
.join('\n');
|
|
628
|
-
}
|
|
629
|
-
replacedTemplate =
|
|
630
|
-
replacedTemplate.substring(0, match.index + precol.length) +
|
|
631
|
-
parameterValue +
|
|
632
|
-
replacedTemplate.substring(match.index + precol.length + parameterName.length + 2);
|
|
633
|
-
};
|
|
634
|
-
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
|
|
635
|
-
.exec(replacedTemplate))) {
|
|
636
|
-
_loop_1();
|
|
637
|
-
}
|
|
638
|
-
// [💫] Check if there are parameters that are not closed properly
|
|
639
|
-
if (/{\w+$/.test(replacedTemplate)) {
|
|
640
|
-
throw new TemplateError('Parameter is not closed');
|
|
641
|
-
}
|
|
642
|
-
// [💫] Check if there are parameters that are not opened properly
|
|
643
|
-
if (/^\w+}/.test(replacedTemplate)) {
|
|
644
|
-
throw new TemplateError('Parameter is not opened');
|
|
645
|
-
}
|
|
646
|
-
return replacedTemplate;
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
/**
|
|
650
|
-
* Counts number of characters in the text
|
|
651
|
-
*/
|
|
652
|
-
function countCharacters(text) {
|
|
653
|
-
// Remove null characters
|
|
654
|
-
text = text.replace(/\0/g, '');
|
|
655
|
-
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
656
|
-
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
|
657
|
-
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
|
658
|
-
text = text.replace(/\p{Extended_Pictographic}(\u{200D}\p{Extended_Pictographic})*/gu, '-');
|
|
659
|
-
return text.length;
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
/**
|
|
663
|
-
* Counts number of lines in the text
|
|
664
|
-
*/
|
|
665
|
-
function countLines(text) {
|
|
666
|
-
if (text === '') {
|
|
667
|
-
return 0;
|
|
668
|
-
}
|
|
669
|
-
return text.split('\n').length;
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
/**
|
|
673
|
-
* Counts number of pages in the text
|
|
674
|
-
*/
|
|
675
|
-
function countPages(text) {
|
|
676
|
-
var sentencesPerPage = 5; // Assuming each page has 5 sentences
|
|
677
|
-
var sentences = text.split(/[.!?]+/).filter(function (sentence) { return sentence.trim() !== ''; });
|
|
678
|
-
var pageCount = Math.ceil(sentences.length / sentencesPerPage);
|
|
679
|
-
return pageCount;
|
|
900
|
+
case 2:
|
|
901
|
+
if (!!_c.done) return [3 /*break*/, 5];
|
|
902
|
+
item = _c.value;
|
|
903
|
+
return [5 /*yield**/, _loop_1(item)];
|
|
904
|
+
case 3:
|
|
905
|
+
_e.sent();
|
|
906
|
+
_e.label = 4;
|
|
907
|
+
case 4:
|
|
908
|
+
_c = _b.next();
|
|
909
|
+
return [3 /*break*/, 2];
|
|
910
|
+
case 5: return [3 /*break*/, 8];
|
|
911
|
+
case 6:
|
|
912
|
+
e_1_1 = _e.sent();
|
|
913
|
+
e_1 = { error: e_1_1 };
|
|
914
|
+
return [3 /*break*/, 8];
|
|
915
|
+
case 7:
|
|
916
|
+
try {
|
|
917
|
+
if (_c && !_c.done && (_d = _b.return)) _d.call(_b);
|
|
918
|
+
}
|
|
919
|
+
finally { if (e_1) throw e_1.error; }
|
|
920
|
+
return [7 /*endfinally*/];
|
|
921
|
+
case 8: return [4 /*yield*/, Promise.all(tasks)];
|
|
922
|
+
case 9:
|
|
923
|
+
_e.sent();
|
|
924
|
+
return [2 /*return*/];
|
|
925
|
+
}
|
|
926
|
+
});
|
|
927
|
+
});
|
|
680
928
|
}
|
|
681
929
|
|
|
682
930
|
/**
|
|
683
|
-
*
|
|
931
|
+
* The maximum number of iterations for a loops
|
|
684
932
|
*/
|
|
685
|
-
|
|
686
|
-
return text.split(/\n\s*\n/).filter(function (paragraph) { return paragraph.trim() !== ''; }).length;
|
|
687
|
-
}
|
|
933
|
+
var LOOP_LIMIT = 1000;
|
|
688
934
|
|
|
689
935
|
/**
|
|
690
|
-
*
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
letters: '\u0041\u24B6\uFF21\u00C0\u00C1\u00C2\u1EA6\u1EA4\u1EAA\u1EA8\u00C3\u0100\u0102\u1EB0\u1EAE\u1EB4\u1EB2\u0226\u01E0\u00C4\u01DE\u1EA2\u00C5\u01FA\u01CD\u0200\u0202\u1EA0\u1EAC\u1EB6\u1E00\u0104\u023A\u2C6F',
|
|
706
|
-
},
|
|
707
|
-
{ base: 'AA', letters: '\uA732' },
|
|
708
|
-
{ base: 'AE', letters: '\u00C6\u01FC\u01E2' },
|
|
709
|
-
{ base: 'AO', letters: '\uA734' },
|
|
710
|
-
{ base: 'AU', letters: '\uA736' },
|
|
711
|
-
{ base: 'AV', letters: '\uA738\uA73A' },
|
|
712
|
-
{ base: 'AY', letters: '\uA73C' },
|
|
713
|
-
{
|
|
714
|
-
base: 'B',
|
|
715
|
-
letters: '\u0042\u24B7\uFF22\u1E02\u1E04\u1E06\u0243\u0182\u0181',
|
|
716
|
-
},
|
|
717
|
-
{
|
|
718
|
-
base: 'C',
|
|
719
|
-
letters: '\u0043\u24B8\uFF23\u0106\u0108\u010A\u010C\u00C7\u1E08\u0187\u023B\uA73E',
|
|
720
|
-
},
|
|
721
|
-
{
|
|
722
|
-
base: 'D',
|
|
723
|
-
letters: '\u0044\u24B9\uFF24\u1E0A\u010E\u1E0C\u1E10\u1E12\u1E0E\u0110\u018B\u018A\u0189\uA779\u00D0',
|
|
724
|
-
},
|
|
725
|
-
{ base: 'DZ', letters: '\u01F1\u01C4' },
|
|
726
|
-
{ base: 'Dz', letters: '\u01F2\u01C5' },
|
|
727
|
-
{
|
|
728
|
-
base: 'E',
|
|
729
|
-
letters: '\u0045\u24BA\uFF25\u00C8\u00C9\u00CA\u1EC0\u1EBE\u1EC4\u1EC2\u1EBC\u0112\u1E14\u1E16\u0114\u0116\u00CB\u1EBA\u011A\u0204\u0206\u1EB8\u1EC6\u0228\u1E1C\u0118\u1E18\u1E1A\u0190\u018E',
|
|
730
|
-
},
|
|
731
|
-
{ base: 'F', letters: '\u0046\u24BB\uFF26\u1E1E\u0191\uA77B' },
|
|
732
|
-
{
|
|
733
|
-
base: 'G',
|
|
734
|
-
letters: '\u0047\u24BC\uFF27\u01F4\u011C\u1E20\u011E\u0120\u01E6\u0122\u01E4\u0193\uA7A0\uA77D\uA77E',
|
|
735
|
-
},
|
|
736
|
-
{
|
|
737
|
-
base: 'H',
|
|
738
|
-
letters: '\u0048\u24BD\uFF28\u0124\u1E22\u1E26\u021E\u1E24\u1E28\u1E2A\u0126\u2C67\u2C75\uA78D',
|
|
739
|
-
},
|
|
740
|
-
{
|
|
741
|
-
base: 'I',
|
|
742
|
-
letters: '\u0049\u24BE\uFF29\u00CC\u00CD\u00CE\u0128\u012A\u012C\u0130\u00CF\u1E2E\u1EC8\u01CF\u0208\u020A\u1ECA\u012E\u1E2C\u0197',
|
|
743
|
-
},
|
|
744
|
-
{ base: 'J', letters: '\u004A\u24BF\uFF2A\u0134\u0248' },
|
|
745
|
-
{
|
|
746
|
-
base: 'K',
|
|
747
|
-
letters: '\u004B\u24C0\uFF2B\u1E30\u01E8\u1E32\u0136\u1E34\u0198\u2C69\uA740\uA742\uA744\uA7A2',
|
|
748
|
-
},
|
|
749
|
-
{
|
|
750
|
-
base: 'L',
|
|
751
|
-
letters: '\u004C\u24C1\uFF2C\u013F\u0139\u013D\u1E36\u1E38\u013B\u1E3C\u1E3A\u0141\u023D\u2C62\u2C60\uA748\uA746\uA780',
|
|
752
|
-
},
|
|
753
|
-
{ base: 'LJ', letters: '\u01C7' },
|
|
754
|
-
{ base: 'Lj', letters: '\u01C8' },
|
|
755
|
-
{ base: 'M', letters: '\u004D\u24C2\uFF2D\u1E3E\u1E40\u1E42\u2C6E\u019C' },
|
|
756
|
-
{
|
|
757
|
-
base: 'N',
|
|
758
|
-
letters: '\u004E\u24C3\uFF2E\u01F8\u0143\u00D1\u1E44\u0147\u1E46\u0145\u1E4A\u1E48\u0220\u019D\uA790\uA7A4',
|
|
759
|
-
},
|
|
760
|
-
{ base: 'NJ', letters: '\u01CA' },
|
|
761
|
-
{ base: 'Nj', letters: '\u01CB' },
|
|
762
|
-
{
|
|
763
|
-
base: 'O',
|
|
764
|
-
letters: '\u004F\u24C4\uFF2F\u00D2\u00D3\u00D4\u1ED2\u1ED0\u1ED6\u1ED4\u00D5\u1E4C\u022C\u1E4E\u014C\u1E50\u1E52\u014E\u022E\u0230\u00D6\u022A\u1ECE\u0150\u01D1\u020C\u020E\u01A0\u1EDC\u1EDA\u1EE0\u1EDE\u1EE2\u1ECC\u1ED8\u01EA\u01EC\u00D8\u01FE\u0186\u019F\uA74A\uA74C',
|
|
765
|
-
},
|
|
766
|
-
{ base: 'OI', letters: '\u01A2' },
|
|
767
|
-
{ base: 'OO', letters: '\uA74E' },
|
|
768
|
-
{ base: 'OU', letters: '\u0222' },
|
|
769
|
-
{ base: 'OE', letters: '\u008C\u0152' },
|
|
770
|
-
{ base: 'oe', letters: '\u009C\u0153' },
|
|
771
|
-
{
|
|
772
|
-
base: 'P',
|
|
773
|
-
letters: '\u0050\u24C5\uFF30\u1E54\u1E56\u01A4\u2C63\uA750\uA752\uA754',
|
|
774
|
-
},
|
|
775
|
-
{ base: 'Q', letters: '\u0051\u24C6\uFF31\uA756\uA758\u024A' },
|
|
776
|
-
{
|
|
777
|
-
base: 'R',
|
|
778
|
-
letters: '\u0052\u24C7\uFF32\u0154\u1E58\u0158\u0210\u0212\u1E5A\u1E5C\u0156\u1E5E\u024C\u2C64\uA75A\uA7A6\uA782',
|
|
779
|
-
},
|
|
780
|
-
{
|
|
781
|
-
base: 'S',
|
|
782
|
-
letters: '\u0053\u24C8\uFF33\u1E9E\u015A\u1E64\u015C\u1E60\u0160\u1E66\u1E62\u1E68\u0218\u015E\u2C7E\uA7A8\uA784',
|
|
783
|
-
},
|
|
784
|
-
{
|
|
785
|
-
base: 'T',
|
|
786
|
-
letters: '\u0054\u24C9\uFF34\u1E6A\u0164\u1E6C\u021A\u0162\u1E70\u1E6E\u0166\u01AC\u01AE\u023E\uA786',
|
|
787
|
-
},
|
|
788
|
-
{ base: 'TZ', letters: '\uA728' },
|
|
789
|
-
{
|
|
790
|
-
base: 'U',
|
|
791
|
-
letters: '\u0055\u24CA\uFF35\u00D9\u00DA\u00DB\u0168\u1E78\u016A\u1E7A\u016C\u00DC\u01DB\u01D7\u01D5\u01D9\u1EE6\u016E\u0170\u01D3\u0214\u0216\u01AF\u1EEA\u1EE8\u1EEE\u1EEC\u1EF0\u1EE4\u1E72\u0172\u1E76\u1E74\u0244',
|
|
792
|
-
},
|
|
793
|
-
{ base: 'V', letters: '\u0056\u24CB\uFF36\u1E7C\u1E7E\u01B2\uA75E\u0245' },
|
|
794
|
-
{ base: 'VY', letters: '\uA760' },
|
|
795
|
-
{
|
|
796
|
-
base: 'W',
|
|
797
|
-
letters: '\u0057\u24CC\uFF37\u1E80\u1E82\u0174\u1E86\u1E84\u1E88\u2C72',
|
|
798
|
-
},
|
|
799
|
-
{ base: 'X', letters: '\u0058\u24CD\uFF38\u1E8A\u1E8C' },
|
|
800
|
-
{
|
|
801
|
-
base: 'Y',
|
|
802
|
-
letters: '\u0059\u24CE\uFF39\u1EF2\u00DD\u0176\u1EF8\u0232\u1E8E\u0178\u1EF6\u1EF4\u01B3\u024E\u1EFE',
|
|
803
|
-
},
|
|
804
|
-
{
|
|
805
|
-
base: 'Z',
|
|
806
|
-
letters: '\u005A\u24CF\uFF3A\u0179\u1E90\u017B\u017D\u1E92\u1E94\u01B5\u0224\u2C7F\u2C6B\uA762',
|
|
807
|
-
},
|
|
808
|
-
{
|
|
809
|
-
base: 'a',
|
|
810
|
-
letters: '\u0061\u24D0\uFF41\u1E9A\u00E0\u00E1\u00E2\u1EA7\u1EA5\u1EAB\u1EA9\u00E3\u0101\u0103\u1EB1\u1EAF\u1EB5\u1EB3\u0227\u01E1\u00E4\u01DF\u1EA3\u00E5\u01FB\u01CE\u0201\u0203\u1EA1\u1EAD\u1EB7\u1E01\u0105\u2C65\u0250',
|
|
811
|
-
},
|
|
812
|
-
{ base: 'aa', letters: '\uA733' },
|
|
813
|
-
{ base: 'ae', letters: '\u00E6\u01FD\u01E3' },
|
|
814
|
-
{ base: 'ao', letters: '\uA735' },
|
|
815
|
-
{ base: 'au', letters: '\uA737' },
|
|
816
|
-
{ base: 'av', letters: '\uA739\uA73B' },
|
|
817
|
-
{ base: 'ay', letters: '\uA73D' },
|
|
818
|
-
{
|
|
819
|
-
base: 'b',
|
|
820
|
-
letters: '\u0062\u24D1\uFF42\u1E03\u1E05\u1E07\u0180\u0183\u0253',
|
|
821
|
-
},
|
|
822
|
-
{
|
|
823
|
-
base: 'c',
|
|
824
|
-
letters: '\u0063\u24D2\uFF43\u0107\u0109\u010B\u010D\u00E7\u1E09\u0188\u023C\uA73F\u2184',
|
|
825
|
-
},
|
|
826
|
-
{
|
|
827
|
-
base: 'd',
|
|
828
|
-
letters: '\u0064\u24D3\uFF44\u1E0B\u010F\u1E0D\u1E11\u1E13\u1E0F\u0111\u018C\u0256\u0257\uA77A',
|
|
829
|
-
},
|
|
830
|
-
{ base: 'dz', letters: '\u01F3\u01C6' },
|
|
831
|
-
{
|
|
832
|
-
base: 'e',
|
|
833
|
-
letters: '\u0065\u24D4\uFF45\u00E8\u00E9\u00EA\u1EC1\u1EBF\u1EC5\u1EC3\u1EBD\u0113\u1E15\u1E17\u0115\u0117\u00EB\u1EBB\u011B\u0205\u0207\u1EB9\u1EC7\u0229\u1E1D\u0119\u1E19\u1E1B\u0247\u025B\u01DD',
|
|
834
|
-
},
|
|
835
|
-
{ base: 'f', letters: '\u0066\u24D5\uFF46\u1E1F\u0192\uA77C' },
|
|
836
|
-
{
|
|
837
|
-
base: 'g',
|
|
838
|
-
letters: '\u0067\u24D6\uFF47\u01F5\u011D\u1E21\u011F\u0121\u01E7\u0123\u01E5\u0260\uA7A1\u1D79\uA77F',
|
|
839
|
-
},
|
|
840
|
-
{
|
|
841
|
-
base: 'h',
|
|
842
|
-
letters: '\u0068\u24D7\uFF48\u0125\u1E23\u1E27\u021F\u1E25\u1E29\u1E2B\u1E96\u0127\u2C68\u2C76\u0265',
|
|
843
|
-
},
|
|
844
|
-
{ base: 'hv', letters: '\u0195' },
|
|
845
|
-
{
|
|
846
|
-
base: 'i',
|
|
847
|
-
letters: '\u0069\u24D8\uFF49\u00EC\u00ED\u00EE\u0129\u012B\u012D\u00EF\u1E2F\u1EC9\u01D0\u0209\u020B\u1ECB\u012F\u1E2D\u0268\u0131',
|
|
848
|
-
},
|
|
849
|
-
{ base: 'j', letters: '\u006A\u24D9\uFF4A\u0135\u01F0\u0249' },
|
|
850
|
-
{
|
|
851
|
-
base: 'k',
|
|
852
|
-
letters: '\u006B\u24DA\uFF4B\u1E31\u01E9\u1E33\u0137\u1E35\u0199\u2C6A\uA741\uA743\uA745\uA7A3',
|
|
853
|
-
},
|
|
854
|
-
{
|
|
855
|
-
base: 'l',
|
|
856
|
-
letters: '\u006C\u24DB\uFF4C\u0140\u013A\u013E\u1E37\u1E39\u013C\u1E3D\u1E3B\u017F\u0142\u019A\u026B\u2C61\uA749\uA781\uA747',
|
|
857
|
-
},
|
|
858
|
-
{ base: 'lj', letters: '\u01C9' },
|
|
859
|
-
{ base: 'm', letters: '\u006D\u24DC\uFF4D\u1E3F\u1E41\u1E43\u0271\u026F' },
|
|
860
|
-
{
|
|
861
|
-
base: 'n',
|
|
862
|
-
letters: '\u006E\u24DD\uFF4E\u01F9\u0144\u00F1\u1E45\u0148\u1E47\u0146\u1E4B\u1E49\u019E\u0272\u0149\uA791\uA7A5',
|
|
863
|
-
},
|
|
864
|
-
{ base: 'nj', letters: '\u01CC' },
|
|
865
|
-
{
|
|
866
|
-
base: 'o',
|
|
867
|
-
letters: '\u006F\u24DE\uFF4F\u00F2\u00F3\u00F4\u1ED3\u1ED1\u1ED7\u1ED5\u00F5\u1E4D\u022D\u1E4F\u014D\u1E51\u1E53\u014F\u022F\u0231\u00F6\u022B\u1ECF\u0151\u01D2\u020D\u020F\u01A1\u1EDD\u1EDB\u1EE1\u1EDF\u1EE3\u1ECD\u1ED9\u01EB\u01ED\u00F8\u01FF\u0254\uA74B\uA74D\u0275',
|
|
868
|
-
},
|
|
869
|
-
{ base: 'oi', letters: '\u01A3' },
|
|
870
|
-
{ base: 'ou', letters: '\u0223' },
|
|
871
|
-
{ base: 'oo', letters: '\uA74F' },
|
|
872
|
-
{
|
|
873
|
-
base: 'p',
|
|
874
|
-
letters: '\u0070\u24DF\uFF50\u1E55\u1E57\u01A5\u1D7D\uA751\uA753\uA755',
|
|
875
|
-
},
|
|
876
|
-
{ base: 'q', letters: '\u0071\u24E0\uFF51\u024B\uA757\uA759' },
|
|
877
|
-
{
|
|
878
|
-
base: 'r',
|
|
879
|
-
letters: '\u0072\u24E1\uFF52\u0155\u1E59\u0159\u0211\u0213\u1E5B\u1E5D\u0157\u1E5F\u024D\u027D\uA75B\uA7A7\uA783',
|
|
880
|
-
},
|
|
881
|
-
{
|
|
882
|
-
base: 's',
|
|
883
|
-
letters: '\u0073\u24E2\uFF53\u00DF\u015B\u1E65\u015D\u1E61\u0161\u1E67\u1E63\u1E69\u0219\u015F\u023F\uA7A9\uA785\u1E9B',
|
|
884
|
-
},
|
|
885
|
-
{
|
|
886
|
-
base: 't',
|
|
887
|
-
letters: '\u0074\u24E3\uFF54\u1E6B\u1E97\u0165\u1E6D\u021B\u0163\u1E71\u1E6F\u0167\u01AD\u0288\u2C66\uA787',
|
|
888
|
-
},
|
|
889
|
-
{ base: 'tz', letters: '\uA729' },
|
|
890
|
-
{
|
|
891
|
-
base: 'u',
|
|
892
|
-
letters: '\u0075\u24E4\uFF55\u00F9\u00FA\u00FB\u0169\u1E79\u016B\u1E7B\u016D\u00FC\u01DC\u01D8\u01D6\u01DA\u1EE7\u016F\u0171\u01D4\u0215\u0217\u01B0\u1EEB\u1EE9\u1EEF\u1EED\u1EF1\u1EE5\u1E73\u0173\u1E77\u1E75\u0289',
|
|
893
|
-
},
|
|
894
|
-
{ base: 'v', letters: '\u0076\u24E5\uFF56\u1E7D\u1E7F\u028B\uA75F\u028C' },
|
|
895
|
-
{ base: 'vy', letters: '\uA761' },
|
|
896
|
-
{
|
|
897
|
-
base: 'w',
|
|
898
|
-
letters: '\u0077\u24E6\uFF57\u1E81\u1E83\u0175\u1E87\u1E85\u1E98\u1E89\u2C73',
|
|
899
|
-
},
|
|
900
|
-
{ base: 'x', letters: '\u0078\u24E7\uFF58\u1E8B\u1E8D' },
|
|
901
|
-
{
|
|
902
|
-
base: 'y',
|
|
903
|
-
letters: '\u0079\u24E8\uFF59\u1EF3\u00FD\u0177\u1EF9\u0233\u1E8F\u00FF\u1EF7\u1E99\u1EF5\u01B4\u024F\u1EFF',
|
|
904
|
-
},
|
|
905
|
-
{
|
|
906
|
-
base: 'z',
|
|
907
|
-
letters: '\u007A\u24E9\uFF5A\u017A\u1E91\u017C\u017E\u1E93\u1E95\u01B6\u0225\u0240\u2C6C\uA763',
|
|
908
|
-
},
|
|
909
|
-
];
|
|
936
|
+
* This error occurs during the parameter replacement in the template
|
|
937
|
+
*
|
|
938
|
+
* Note: This is a kindof subtype of PromptbookExecutionError because it occurs during the execution of the pipeline
|
|
939
|
+
*/
|
|
940
|
+
var TemplateError = /** @class */ (function (_super) {
|
|
941
|
+
__extends(TemplateError, _super);
|
|
942
|
+
function TemplateError(message) {
|
|
943
|
+
var _this = _super.call(this, message) || this;
|
|
944
|
+
_this.name = 'TemplateError';
|
|
945
|
+
Object.setPrototypeOf(_this, TemplateError.prototype);
|
|
946
|
+
return _this;
|
|
947
|
+
}
|
|
948
|
+
return TemplateError;
|
|
949
|
+
}(Error));
|
|
950
|
+
|
|
910
951
|
/**
|
|
911
|
-
*
|
|
912
|
-
* Contains lowercase and uppercase separatelly
|
|
952
|
+
* Replaces parameters in template with values from parameters object
|
|
913
953
|
*
|
|
914
|
-
*
|
|
915
|
-
*
|
|
916
|
-
*
|
|
917
|
-
*
|
|
954
|
+
* @param template the template with parameters in {curly} braces
|
|
955
|
+
* @param parameters the object with parameters
|
|
956
|
+
* @returns the template with replaced parameters
|
|
957
|
+
* @throws {TemplateError} if parameter is not defined, not closed, or not opened
|
|
958
|
+
*
|
|
959
|
+
* @private within the createPromptbookExecutor
|
|
918
960
|
*/
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
var
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
961
|
+
function replaceParameters(template, parameters) {
|
|
962
|
+
var replacedTemplate = template;
|
|
963
|
+
var match;
|
|
964
|
+
var loopLimit = LOOP_LIMIT;
|
|
965
|
+
var _loop_1 = function () {
|
|
966
|
+
if (loopLimit-- < 0) {
|
|
967
|
+
throw new UnexpectedError('Loop limit reached during parameters replacement in `replaceParameters`');
|
|
968
|
+
}
|
|
969
|
+
var precol = match.groups.precol;
|
|
970
|
+
var parameterName = match.groups.parameterName;
|
|
971
|
+
if (parameterName === '') {
|
|
972
|
+
return "continue";
|
|
973
|
+
}
|
|
974
|
+
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
|
|
975
|
+
throw new TemplateError('Parameter is already opened or not closed');
|
|
976
|
+
}
|
|
977
|
+
if (parameters[parameterName] === undefined) {
|
|
978
|
+
throw new TemplateError("Parameter {".concat(parameterName, "} is not defined"));
|
|
979
|
+
}
|
|
980
|
+
var parameterValue = parameters[parameterName];
|
|
981
|
+
if (parameterValue === undefined) {
|
|
982
|
+
throw new TemplateError("Parameter {".concat(parameterName, "} is not defined"));
|
|
983
|
+
}
|
|
984
|
+
parameterValue = parameterValue.toString();
|
|
985
|
+
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
986
|
+
parameterValue = parameterValue
|
|
987
|
+
.split('\n')
|
|
988
|
+
.map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
|
|
989
|
+
.join('\n');
|
|
990
|
+
}
|
|
991
|
+
replacedTemplate =
|
|
992
|
+
replacedTemplate.substring(0, match.index + precol.length) +
|
|
993
|
+
parameterValue +
|
|
994
|
+
replacedTemplate.substring(match.index + precol.length + parameterName.length + 2);
|
|
995
|
+
};
|
|
996
|
+
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
|
|
997
|
+
.exec(replacedTemplate))) {
|
|
998
|
+
_loop_1();
|
|
999
|
+
}
|
|
1000
|
+
// [💫] Check if there are parameters that are not closed properly
|
|
1001
|
+
if (/{\w+$/.test(replacedTemplate)) {
|
|
1002
|
+
throw new TemplateError('Parameter is not closed');
|
|
1003
|
+
}
|
|
1004
|
+
// [💫] Check if there are parameters that are not opened properly
|
|
1005
|
+
if (/^\w+}/.test(replacedTemplate)) {
|
|
1006
|
+
throw new TemplateError('Parameter is not opened');
|
|
926
1007
|
}
|
|
1008
|
+
return replacedTemplate;
|
|
927
1009
|
}
|
|
928
|
-
// <- TODO: [🍓] Put to maker function to save execution time if not needed
|
|
929
|
-
/*
|
|
930
|
-
@see https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript
|
|
931
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
932
|
-
you may not use this file except in compliance with the License.
|
|
933
|
-
You may obtain a copy of the License at
|
|
934
1010
|
|
|
935
|
-
|
|
1011
|
+
/**
|
|
1012
|
+
* Counts number of characters in the text
|
|
1013
|
+
*/
|
|
1014
|
+
function countCharacters(text) {
|
|
1015
|
+
// Remove null characters
|
|
1016
|
+
text = text.replace(/\0/g, '');
|
|
1017
|
+
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
1018
|
+
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
|
1019
|
+
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
|
1020
|
+
text = text.replace(/\p{Extended_Pictographic}(\u{200D}\p{Extended_Pictographic})*/gu, '-');
|
|
1021
|
+
return text.length;
|
|
1022
|
+
}
|
|
936
1023
|
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
1024
|
+
/**
|
|
1025
|
+
* Counts number of lines in the text
|
|
1026
|
+
*/
|
|
1027
|
+
function countLines(text) {
|
|
1028
|
+
if (text === '') {
|
|
1029
|
+
return 0;
|
|
1030
|
+
}
|
|
1031
|
+
return text.split('\n').length;
|
|
1032
|
+
}
|
|
943
1033
|
|
|
944
1034
|
/**
|
|
945
|
-
*
|
|
1035
|
+
* Counts number of pages in the text
|
|
946
1036
|
*/
|
|
947
|
-
function
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
1037
|
+
function countPages(text) {
|
|
1038
|
+
var sentencesPerPage = 5; // Assuming each page has 5 sentences
|
|
1039
|
+
var sentences = text.split(/[.!?]+/).filter(function (sentence) { return sentence.trim() !== ''; });
|
|
1040
|
+
var pageCount = Math.ceil(sentences.length / sentencesPerPage);
|
|
1041
|
+
return pageCount;
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
/**
|
|
1045
|
+
* Counts number of paragraphs in the text
|
|
1046
|
+
*/
|
|
1047
|
+
function countParagraphs(text) {
|
|
1048
|
+
return text.split(/\n\s*\n/).filter(function (paragraph) { return paragraph.trim() !== ''; }).length;
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
/**
|
|
1052
|
+
* Split text into sentences
|
|
1053
|
+
*/
|
|
1054
|
+
function splitIntoSentences(text) {
|
|
1055
|
+
return text.split(/[.!?]+/).filter(function (sentence) { return sentence.trim() !== ''; });
|
|
1056
|
+
}
|
|
1057
|
+
/**
|
|
1058
|
+
* Counts number of sentences in the text
|
|
1059
|
+
*/
|
|
1060
|
+
function countSentences(text) {
|
|
1061
|
+
return splitIntoSentences(text).length;
|
|
952
1062
|
}
|
|
953
1063
|
|
|
954
1064
|
/**
|
|
@@ -1263,116 +1373,6 @@
|
|
|
1263
1373
|
.filter(function (value) { return value !== ''; });
|
|
1264
1374
|
}
|
|
1265
1375
|
|
|
1266
|
-
/* tslint:disable */
|
|
1267
|
-
function normalizeToKebabCase(sentence) {
|
|
1268
|
-
var e_1, _a;
|
|
1269
|
-
sentence = removeDiacritics(sentence);
|
|
1270
|
-
var charType;
|
|
1271
|
-
var lastCharType = 'OTHER';
|
|
1272
|
-
var normalizedName = '';
|
|
1273
|
-
try {
|
|
1274
|
-
for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
|
|
1275
|
-
var char = sentence_1_1.value;
|
|
1276
|
-
var normalizedChar = void 0;
|
|
1277
|
-
if (/^[a-z]$/.test(char)) {
|
|
1278
|
-
charType = 'LOWERCASE';
|
|
1279
|
-
normalizedChar = char;
|
|
1280
|
-
}
|
|
1281
|
-
else if (/^[A-Z]$/.test(char)) {
|
|
1282
|
-
charType = 'UPPERCASE';
|
|
1283
|
-
normalizedChar = char.toLowerCase();
|
|
1284
|
-
}
|
|
1285
|
-
else if (/^[0-9]$/.test(char)) {
|
|
1286
|
-
charType = 'NUMBER';
|
|
1287
|
-
normalizedChar = char;
|
|
1288
|
-
}
|
|
1289
|
-
else if (/^\/$/.test(char)) {
|
|
1290
|
-
charType = 'SLASH';
|
|
1291
|
-
normalizedChar = char;
|
|
1292
|
-
}
|
|
1293
|
-
else {
|
|
1294
|
-
charType = 'OTHER';
|
|
1295
|
-
normalizedChar = '-';
|
|
1296
|
-
}
|
|
1297
|
-
if (charType !== lastCharType &&
|
|
1298
|
-
!(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
|
|
1299
|
-
!(lastCharType === 'NUMBER') &&
|
|
1300
|
-
!(charType === 'NUMBER')) {
|
|
1301
|
-
normalizedName += '-';
|
|
1302
|
-
}
|
|
1303
|
-
normalizedName += normalizedChar;
|
|
1304
|
-
lastCharType = charType;
|
|
1305
|
-
}
|
|
1306
|
-
}
|
|
1307
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1308
|
-
finally {
|
|
1309
|
-
try {
|
|
1310
|
-
if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
|
|
1311
|
-
}
|
|
1312
|
-
finally { if (e_1) throw e_1.error; }
|
|
1313
|
-
}
|
|
1314
|
-
normalizedName = normalizedName.split(/-+/g).join('-');
|
|
1315
|
-
normalizedName = normalizedName.split(/-?\/-?/g).join('/');
|
|
1316
|
-
normalizedName = normalizedName.replace(/^-/, '');
|
|
1317
|
-
normalizedName = normalizedName.replace(/-$/, '');
|
|
1318
|
-
return normalizedName;
|
|
1319
|
-
}
|
|
1320
|
-
|
|
1321
|
-
/* tslint:disable */
|
|
1322
|
-
function normalizeTo_camelCase(sentence, __firstLetterCapital) {
|
|
1323
|
-
var e_1, _a;
|
|
1324
|
-
if (__firstLetterCapital === void 0) { __firstLetterCapital = false; }
|
|
1325
|
-
var charType;
|
|
1326
|
-
var lastCharType = null;
|
|
1327
|
-
var normalizedName = '';
|
|
1328
|
-
try {
|
|
1329
|
-
for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
|
|
1330
|
-
var char = sentence_1_1.value;
|
|
1331
|
-
var normalizedChar = void 0;
|
|
1332
|
-
if (/^[a-z]$/.test(char)) {
|
|
1333
|
-
charType = 'LOWERCASE';
|
|
1334
|
-
normalizedChar = char;
|
|
1335
|
-
}
|
|
1336
|
-
else if (/^[A-Z]$/.test(char)) {
|
|
1337
|
-
charType = 'UPPERCASE';
|
|
1338
|
-
normalizedChar = char.toLowerCase();
|
|
1339
|
-
}
|
|
1340
|
-
else if (/^[0-9]$/.test(char)) {
|
|
1341
|
-
charType = 'NUMBER';
|
|
1342
|
-
normalizedChar = char;
|
|
1343
|
-
}
|
|
1344
|
-
else {
|
|
1345
|
-
charType = 'OTHER';
|
|
1346
|
-
normalizedChar = '';
|
|
1347
|
-
}
|
|
1348
|
-
if (!lastCharType) {
|
|
1349
|
-
if (__firstLetterCapital) {
|
|
1350
|
-
normalizedChar = normalizedChar.toUpperCase(); //TODO: DRY
|
|
1351
|
-
}
|
|
1352
|
-
}
|
|
1353
|
-
else if (charType !== lastCharType &&
|
|
1354
|
-
!(charType === 'LOWERCASE' && lastCharType === 'UPPERCASE') &&
|
|
1355
|
-
!(lastCharType === 'NUMBER') &&
|
|
1356
|
-
!(charType === 'NUMBER')) {
|
|
1357
|
-
normalizedChar = normalizedChar.toUpperCase(); //TODO: [🌺] DRY
|
|
1358
|
-
}
|
|
1359
|
-
normalizedName += normalizedChar;
|
|
1360
|
-
lastCharType = charType;
|
|
1361
|
-
}
|
|
1362
|
-
}
|
|
1363
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1364
|
-
finally {
|
|
1365
|
-
try {
|
|
1366
|
-
if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
|
|
1367
|
-
}
|
|
1368
|
-
finally { if (e_1) throw e_1.error; }
|
|
1369
|
-
}
|
|
1370
|
-
return normalizedName;
|
|
1371
|
-
}
|
|
1372
|
-
/**
|
|
1373
|
-
* TODO: [🌺] Use some intermediate util splitWords
|
|
1374
|
-
*/
|
|
1375
|
-
|
|
1376
1376
|
function normalizeTo_PascalCase(sentence) {
|
|
1377
1377
|
return normalizeTo_camelCase(sentence, true);
|
|
1378
1378
|
}
|
|
@@ -1427,9 +1427,7 @@
|
|
|
1427
1427
|
function searchKeywords(haystack, needle) {
|
|
1428
1428
|
var e_1, _a;
|
|
1429
1429
|
var _loop_1 = function (needleWord) {
|
|
1430
|
-
if (!__spreadArray([], __read(haystack), false).some(function (haystackWord) {
|
|
1431
|
-
return haystackWord.substring(0, needleWord.length) === needleWord;
|
|
1432
|
-
})) {
|
|
1430
|
+
if (!__spreadArray([], __read(haystack), false).some(function (haystackWord) { return haystackWord.substring(0, needleWord.length) === needleWord; })) {
|
|
1433
1431
|
return { value: false };
|
|
1434
1432
|
}
|
|
1435
1433
|
};
|