@promptbook/utils 0.102.0-4 → 0.102.0-6
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 +208 -231
- package/esm/index.es.js.map +1 -1
- package/esm/typings/books/index.d.ts +81 -0
- package/esm/typings/src/_packages/components.index.d.ts +2 -0
- package/esm/typings/src/_packages/markdown-utils.index.d.ts +4 -0
- package/esm/typings/src/_packages/types.index.d.ts +8 -6
- package/esm/typings/src/_packages/utils.index.d.ts +12 -14
- package/esm/typings/src/book-2.0/agent-source/createAgentModelRequirements.d.ts +1 -1
- package/esm/typings/src/book-2.0/utils/generateGravatarUrl.d.ts +1 -1
- package/esm/typings/src/book-2.0/utils/generatePlaceholderAgentProfileImageUrl.d.ts +1 -1
- package/esm/typings/src/book-components/BookEditor/BookEditor.d.ts +1 -1
- package/esm/typings/src/book-components/BookEditor/BookEditorInner.d.ts +1 -1
- package/esm/typings/src/book-components/Chat/Chat/Chat.d.ts +1 -5
- package/esm/typings/src/book-components/Chat/Chat/ChatMessageItem.d.ts +27 -0
- package/esm/typings/src/book-components/Chat/Chat/ChatProps.d.ts +13 -6
- package/esm/typings/src/book-components/Chat/Chat/constants.d.ts +7 -0
- package/esm/typings/src/book-components/Chat/LlmChat/LlmChatProps.d.ts +1 -1
- package/esm/typings/src/book-components/Chat/MockedChat/MockedChat.d.ts +1 -1
- package/esm/typings/src/book-components/Chat/MockedChat/constants.d.ts +1 -1
- package/esm/typings/src/book-components/Chat/save/_common/ChatSaveFormatDefinition.d.ts +1 -1
- package/esm/typings/src/book-components/Chat/save/_common/getChatSaveFormatDefinitions.d.ts +2 -2
- package/esm/typings/src/book-components/Chat/save/_common/string_chat_format_name.d.ts +1 -1
- package/esm/typings/src/execution/LlmExecutionToolsConstructor.d.ts +1 -1
- package/esm/typings/src/execution/execution-report/countWorkingDuration.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/$llmToolsMetadataRegister.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/$llmToolsRegister.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/$registeredLlmToolsMessage.d.ts +1 -2
- package/esm/typings/src/llm-providers/_common/register/LlmToolsConfiguration.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/LlmToolsMetadata.d.ts +1 -1
- package/esm/typings/src/llm-providers/_multiple/joinLlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/agent/register-configuration.d.ts +1 -1
- package/esm/typings/src/llm-providers/agent/register-constructor.d.ts +1 -1
- package/esm/typings/src/llm-providers/anthropic-claude/register-configuration.d.ts +1 -1
- package/esm/typings/src/llm-providers/anthropic-claude/register-constructor.d.ts +1 -1
- package/esm/typings/src/llm-providers/azure-openai/register-configuration.d.ts +1 -1
- package/esm/typings/src/llm-providers/azure-openai/register-constructor.d.ts +1 -1
- package/esm/typings/src/llm-providers/deepseek/register-configuration.d.ts +1 -1
- package/esm/typings/src/llm-providers/deepseek/register-constructor.d.ts +1 -1
- package/esm/typings/src/llm-providers/google/register-configuration.d.ts +1 -1
- package/esm/typings/src/llm-providers/google/register-constructor.d.ts +1 -1
- package/esm/typings/src/llm-providers/ollama/register-configuration.d.ts +1 -1
- package/esm/typings/src/llm-providers/ollama/register-constructor.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +1 -3
- package/esm/typings/src/llm-providers/openai/OpenAiCompatibleExecutionTools.d.ts +5 -1
- package/esm/typings/src/llm-providers/openai/register-configuration.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/register-constructor.d.ts +1 -1
- package/esm/typings/src/scrapers/_boilerplate/register-constructor.d.ts +1 -1
- package/esm/typings/src/scrapers/_boilerplate/register-metadata.d.ts +1 -1
- package/esm/typings/src/scrapers/_common/register/$scrapersMetadataRegister.d.ts +1 -1
- package/esm/typings/src/scrapers/_common/register/$scrapersRegister.d.ts +1 -1
- package/esm/typings/src/scrapers/_common/register/ScraperAndConverterMetadata.d.ts +2 -4
- package/esm/typings/src/scrapers/_common/register/ScraperConstructor.d.ts +1 -1
- package/esm/typings/src/scrapers/document/register-constructor.d.ts +1 -1
- package/esm/typings/src/scrapers/document/register-metadata.d.ts +1 -1
- package/esm/typings/src/scrapers/document-legacy/register-constructor.d.ts +1 -1
- package/esm/typings/src/scrapers/document-legacy/register-metadata.d.ts +1 -1
- package/esm/typings/src/scrapers/markdown/register-constructor.d.ts +1 -1
- package/esm/typings/src/scrapers/markdown/register-metadata.d.ts +1 -1
- package/esm/typings/src/scrapers/markitdown/register-constructor.d.ts +1 -1
- package/esm/typings/src/scrapers/markitdown/register-metadata.d.ts +1 -1
- package/esm/typings/src/scrapers/pdf/register-constructor.d.ts +1 -1
- package/esm/typings/src/scrapers/pdf/register-metadata.d.ts +1 -1
- package/esm/typings/src/scrapers/website/register-constructor.d.ts +1 -1
- package/esm/typings/src/scrapers/website/register-metadata.d.ts +1 -1
- package/esm/typings/src/scripting/javascript/postprocessing-functions.d.ts +6 -6
- package/esm/typings/src/types/Prompt.d.ts +5 -0
- package/esm/typings/src/utils/markdown/createMarkdownChart.d.ts +1 -1
- package/esm/typings/src/utils/markdown/humanizeAiText.d.ts +1 -1
- package/esm/typings/src/utils/markdown/humanizeAiTextEllipsis.d.ts +1 -1
- package/esm/typings/src/utils/markdown/humanizeAiTextEmdashed.d.ts +1 -1
- package/esm/typings/src/utils/markdown/humanizeAiTextQuotes.d.ts +1 -1
- package/esm/typings/src/utils/markdown/humanizeAiTextWhitespace.d.ts +1 -1
- package/esm/typings/src/utils/markdown/promptbookifyAiText.d.ts +1 -1
- package/esm/typings/src/utils/{trimCodeBlock.d.ts → markdown/trimCodeBlock.d.ts} +1 -1
- package/esm/typings/src/utils/{trimEndOfCodeBlock.d.ts → markdown/trimEndOfCodeBlock.d.ts} +1 -1
- package/esm/typings/src/utils/{$Register.d.ts → misc/$Register.d.ts} +2 -2
- package/esm/typings/src/utils/{$getCurrentDate.d.ts → misc/$getCurrentDate.d.ts} +1 -1
- package/esm/typings/src/utils/{arrayableToArray.d.ts → misc/arrayableToArray.d.ts} +1 -1
- package/esm/typings/src/utils/misc/debounce.d.ts +5 -0
- package/esm/typings/src/utils/{emojis.d.ts → misc/emojis.d.ts} +1 -1
- package/esm/typings/src/utils/misc/injectCssModuleIntoShadowRoot.d.ts +20 -0
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +208 -232
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/book-components/BookEditor/injectCssModuleIntoShadowRoot.d.ts +0 -11
- /package/esm/typings/src/utils/{trimCodeBlock.test.d.ts → markdown/trimCodeBlock.test.d.ts} +0 -0
- /package/esm/typings/src/utils/{trimEndOfCodeBlock.test.d.ts → markdown/trimEndOfCodeBlock.test.d.ts} +0 -0
- /package/esm/typings/src/utils/{FromtoItems.d.ts → misc/FromtoItems.d.ts} +0 -0
- /package/esm/typings/src/utils/{arrayableToArray.test.d.ts → misc/arrayableToArray.test.d.ts} +0 -0
- /package/esm/typings/src/utils/{parseNumber.d.ts → misc/parseNumber.d.ts} +0 -0
- /package/esm/typings/src/utils/{parseNumber.test.d.ts → misc/parseNumber.test.d.ts} +0 -0
- /package/esm/typings/src/utils/{removeEmojis.d.ts → normalization/removeEmojis.d.ts} +0 -0
- /package/esm/typings/src/utils/{removeEmojis.test.d.ts → normalization/removeEmojis.test.d.ts} +0 -0
- /package/esm/typings/src/utils/{removeQuotes.d.ts → normalization/removeQuotes.d.ts} +0 -0
- /package/esm/typings/src/utils/{removeQuotes.test.d.ts → normalization/removeQuotes.test.d.ts} +0 -0
- /package/esm/typings/src/utils/{unwrapResult.d.ts → normalization/unwrapResult.d.ts} +0 -0
- /package/esm/typings/src/utils/{unwrapResult.test.d.ts → normalization/unwrapResult.test.d.ts} +0 -0
package/esm/index.es.js
CHANGED
@@ -16,7 +16,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
16
16
|
* @generated
|
17
17
|
* @see https://github.com/webgptorg/promptbook
|
18
18
|
*/
|
19
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.102.0-
|
19
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.102.0-6';
|
20
20
|
/**
|
21
21
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
22
22
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
@@ -546,24 +546,6 @@ function normalizeTo_camelCase(text, _isFirstLetterCapital = false) {
|
|
546
546
|
* TODO: [🌺] Use some intermediate util splitWords
|
547
547
|
*/
|
548
548
|
|
549
|
-
/**
|
550
|
-
* Removes emojis from a string and fix whitespaces
|
551
|
-
*
|
552
|
-
* Note: [🔂] This function is idempotent.
|
553
|
-
*
|
554
|
-
* @param text with emojis
|
555
|
-
* @returns text without emojis
|
556
|
-
* @public exported from `@promptbook/utils`
|
557
|
-
*/
|
558
|
-
function removeEmojis(text) {
|
559
|
-
// Replace emojis (and also ZWJ sequence) with hyphens
|
560
|
-
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
561
|
-
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
562
|
-
text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
|
563
|
-
text = text.replace(/\p{Extended_Pictographic}/gu, '');
|
564
|
-
return text;
|
565
|
-
}
|
566
|
-
|
567
549
|
/**
|
568
550
|
* Tests if given string is valid file path.
|
569
551
|
*
|
@@ -964,6 +946,24 @@ function normalizeToKebabCase(text) {
|
|
964
946
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
965
947
|
*/
|
966
948
|
|
949
|
+
/**
|
950
|
+
* Removes emojis from a string and fix whitespaces
|
951
|
+
*
|
952
|
+
* Note: [🔂] This function is idempotent.
|
953
|
+
*
|
954
|
+
* @param text with emojis
|
955
|
+
* @returns text without emojis
|
956
|
+
* @public exported from `@promptbook/utils`
|
957
|
+
*/
|
958
|
+
function removeEmojis(text) {
|
959
|
+
// Replace emojis (and also ZWJ sequence) with hyphens
|
960
|
+
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
961
|
+
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
962
|
+
text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
|
963
|
+
text = text.replace(/\p{Extended_Pictographic}/gu, '');
|
964
|
+
return text;
|
965
|
+
}
|
966
|
+
|
967
967
|
/**
|
968
968
|
* Converts a title string into a normalized name.
|
969
969
|
*
|
@@ -1819,18 +1819,6 @@ const promptTemplate = prompt;
|
|
1819
1819
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
1820
1820
|
*/
|
1821
1821
|
|
1822
|
-
/**
|
1823
|
-
* Simple wrapper `new Date().toISOString()`
|
1824
|
-
*
|
1825
|
-
* Note: `$` is used to indicate that this function is not a pure function - it is not deterministic because it depends on the current time
|
1826
|
-
*
|
1827
|
-
* @returns string_date branded type
|
1828
|
-
* @public exported from `@promptbook/utils`
|
1829
|
-
*/
|
1830
|
-
function $getCurrentDate() {
|
1831
|
-
return new Date().toISOString();
|
1832
|
-
}
|
1833
|
-
|
1834
1822
|
/**
|
1835
1823
|
* Detects if the code is running in a browser environment in main thread (Not in a web worker)
|
1836
1824
|
*
|
@@ -2046,6 +2034,99 @@ const CountUtils = {
|
|
2046
2034
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
2047
2035
|
*/
|
2048
2036
|
|
2037
|
+
/**
|
2038
|
+
* Simple wrapper `new Date().toISOString()`
|
2039
|
+
*
|
2040
|
+
* Note: `$` is used to indicate that this function is not a pure function - it is not deterministic because it depends on the current time
|
2041
|
+
*
|
2042
|
+
* @returns string_date branded type
|
2043
|
+
* @public exported from `@promptbook/utils`
|
2044
|
+
*/
|
2045
|
+
function $getCurrentDate() {
|
2046
|
+
return new Date().toISOString();
|
2047
|
+
}
|
2048
|
+
|
2049
|
+
/**
|
2050
|
+
* @public exported from `@promptbook/utils`
|
2051
|
+
*/
|
2052
|
+
function debounce(fn, delay) {
|
2053
|
+
let timeout = null;
|
2054
|
+
return (...args) => {
|
2055
|
+
if (timeout)
|
2056
|
+
clearTimeout(timeout);
|
2057
|
+
timeout = setTimeout(() => fn(...args), delay);
|
2058
|
+
};
|
2059
|
+
}
|
2060
|
+
|
2061
|
+
/**
|
2062
|
+
* Function parseNumber will parse number from string
|
2063
|
+
*
|
2064
|
+
* Note: [🔂] This function is idempotent.
|
2065
|
+
* Unlike Number.parseInt, Number.parseFloat it will never ever result in NaN
|
2066
|
+
* Note: it also works only with decimal numbers
|
2067
|
+
*
|
2068
|
+
* @returns parsed number
|
2069
|
+
* @throws {ParseError} if the value is not a number
|
2070
|
+
*
|
2071
|
+
* @public exported from `@promptbook/utils`
|
2072
|
+
*/
|
2073
|
+
function parseNumber(value) {
|
2074
|
+
const originalValue = value;
|
2075
|
+
if (typeof value === 'number') {
|
2076
|
+
value = value.toString(); // <- TODO: Maybe more efficient way to do this
|
2077
|
+
}
|
2078
|
+
if (typeof value !== 'string') {
|
2079
|
+
return 0;
|
2080
|
+
}
|
2081
|
+
value = value.trim();
|
2082
|
+
if (value.startsWith('+')) {
|
2083
|
+
return parseNumber(value.substring(1));
|
2084
|
+
}
|
2085
|
+
if (value.startsWith('-')) {
|
2086
|
+
const number = parseNumber(value.substring(1));
|
2087
|
+
if (number === 0) {
|
2088
|
+
return 0; // <- Note: To prevent -0
|
2089
|
+
}
|
2090
|
+
return -number;
|
2091
|
+
}
|
2092
|
+
value = value.replace(/,/g, '.');
|
2093
|
+
value = value.toUpperCase();
|
2094
|
+
if (value === '') {
|
2095
|
+
return 0;
|
2096
|
+
}
|
2097
|
+
if (value === '♾' || value.startsWith('INF')) {
|
2098
|
+
return Infinity;
|
2099
|
+
}
|
2100
|
+
if (value.includes('/')) {
|
2101
|
+
const [numerator_, denominator_] = value.split('/');
|
2102
|
+
const numerator = parseNumber(numerator_);
|
2103
|
+
const denominator = parseNumber(denominator_);
|
2104
|
+
if (denominator === 0) {
|
2105
|
+
throw new ParseError(`Unable to parse number from "${originalValue}" because denominator is zero`);
|
2106
|
+
}
|
2107
|
+
return numerator / denominator;
|
2108
|
+
}
|
2109
|
+
if (/^(NAN|NULL|NONE|UNDEFINED|ZERO|NO.*)$/.test(value)) {
|
2110
|
+
return 0;
|
2111
|
+
}
|
2112
|
+
if (value.includes('E')) {
|
2113
|
+
const [significand, exponent] = value.split('E');
|
2114
|
+
return parseNumber(significand) * 10 ** parseNumber(exponent);
|
2115
|
+
}
|
2116
|
+
if (!/^[0-9.]+$/.test(value) || value.split('.').length > 2) {
|
2117
|
+
throw new ParseError(`Unable to parse number from "${originalValue}"`);
|
2118
|
+
}
|
2119
|
+
const num = parseFloat(value);
|
2120
|
+
if (isNaN(num)) {
|
2121
|
+
throw new ParseError(`Unexpected NaN when parsing number from "${originalValue}"`);
|
2122
|
+
}
|
2123
|
+
return num;
|
2124
|
+
}
|
2125
|
+
/**
|
2126
|
+
* TODO: Maybe use sth. like safe-eval in fraction/calculation case @see https://www.npmjs.com/package/safe-eval
|
2127
|
+
* TODO: [🧠][🌻] Maybe export through `@promptbook/markdown-utils` not `@promptbook/utils`
|
2128
|
+
*/
|
2129
|
+
|
2049
2130
|
/**
|
2050
2131
|
* Makes first letter of a string uppercase
|
2051
2132
|
*
|
@@ -2261,6 +2342,30 @@ function parseKeywords(input) {
|
|
2261
2342
|
* TODO: [🌺] Use some intermediate util splitWords
|
2262
2343
|
*/
|
2263
2344
|
|
2345
|
+
/**
|
2346
|
+
* Removes quotes from a string
|
2347
|
+
*
|
2348
|
+
* Note: [🔂] This function is idempotent.
|
2349
|
+
* Tip: This is very useful for post-processing of the result of the LLM model
|
2350
|
+
* Note: This function removes only the same quotes from the beginning and the end of the string
|
2351
|
+
* Note: There are two similar functions:
|
2352
|
+
* - `removeQuotes` which removes only bounding quotes
|
2353
|
+
* - `unwrapResult` which removes whole introduce sentence
|
2354
|
+
*
|
2355
|
+
* @param text optionally quoted text
|
2356
|
+
* @returns text without quotes
|
2357
|
+
* @public exported from `@promptbook/utils`
|
2358
|
+
*/
|
2359
|
+
function removeQuotes(text) {
|
2360
|
+
if (text.startsWith('"') && text.endsWith('"')) {
|
2361
|
+
return text.slice(1, -1);
|
2362
|
+
}
|
2363
|
+
if (text.startsWith("'") && text.endsWith("'")) {
|
2364
|
+
return text.slice(1, -1);
|
2365
|
+
}
|
2366
|
+
return text;
|
2367
|
+
}
|
2368
|
+
|
2264
2369
|
/**
|
2265
2370
|
* Searches set of keywords for a specific keyword
|
2266
2371
|
*
|
@@ -2292,6 +2397,77 @@ function suffixUrl(value, suffix) {
|
|
2292
2397
|
return (baseUrl + normalizedSuffix);
|
2293
2398
|
}
|
2294
2399
|
|
2400
|
+
/**
|
2401
|
+
* Removes quotes and optional introduce text from a string
|
2402
|
+
*
|
2403
|
+
* Tip: This is very useful for post-processing of the result of the LLM model
|
2404
|
+
* Note: This function trims the text and removes whole introduce sentence if it is present
|
2405
|
+
* Note: There are two similar functions:
|
2406
|
+
* - `removeQuotes` which removes only bounding quotes
|
2407
|
+
* - `unwrapResult` which removes whole introduce sentence
|
2408
|
+
*
|
2409
|
+
* @param text optionally quoted text
|
2410
|
+
* @returns text without quotes
|
2411
|
+
* @public exported from `@promptbook/utils`
|
2412
|
+
*/
|
2413
|
+
function unwrapResult(text, options) {
|
2414
|
+
const { isTrimmed = true, isIntroduceSentenceRemoved = true } = options || {};
|
2415
|
+
let trimmedText = text;
|
2416
|
+
// Remove leading and trailing spaces and newlines
|
2417
|
+
if (isTrimmed) {
|
2418
|
+
trimmedText = spaceTrim$2(trimmedText);
|
2419
|
+
}
|
2420
|
+
let processedText = trimmedText;
|
2421
|
+
if (isIntroduceSentenceRemoved) {
|
2422
|
+
const introduceSentenceRegex = /^[a-zěščřžýáíéúů:\s]*:\s*/i;
|
2423
|
+
if (introduceSentenceRegex.test(text)) {
|
2424
|
+
// Remove the introduce sentence and quotes by replacing it with an empty string
|
2425
|
+
processedText = processedText.replace(introduceSentenceRegex, '');
|
2426
|
+
}
|
2427
|
+
processedText = spaceTrim$2(processedText);
|
2428
|
+
}
|
2429
|
+
if (processedText.length < 3) {
|
2430
|
+
return trimmedText;
|
2431
|
+
}
|
2432
|
+
if (processedText.includes('\n')) {
|
2433
|
+
return trimmedText;
|
2434
|
+
}
|
2435
|
+
// Remove the quotes by extracting the substring without the first and last characters
|
2436
|
+
const unquotedText = processedText.slice(1, -1);
|
2437
|
+
// Check if the text starts and ends with quotes
|
2438
|
+
if ([
|
2439
|
+
['"', '"'],
|
2440
|
+
["'", "'"],
|
2441
|
+
['`', '`'],
|
2442
|
+
['*', '*'],
|
2443
|
+
['_', '_'],
|
2444
|
+
['„', '“'],
|
2445
|
+
['«', '»'] /* <- QUOTES to config */,
|
2446
|
+
].some(([startQuote, endQuote]) => {
|
2447
|
+
if (!processedText.startsWith(startQuote)) {
|
2448
|
+
return false;
|
2449
|
+
}
|
2450
|
+
if (!processedText.endsWith(endQuote)) {
|
2451
|
+
return false;
|
2452
|
+
}
|
2453
|
+
if (unquotedText.includes(startQuote) && !unquotedText.includes(endQuote)) {
|
2454
|
+
return false;
|
2455
|
+
}
|
2456
|
+
if (!unquotedText.includes(startQuote) && unquotedText.includes(endQuote)) {
|
2457
|
+
return false;
|
2458
|
+
}
|
2459
|
+
return true;
|
2460
|
+
})) {
|
2461
|
+
return unwrapResult(unquotedText, { isTrimmed: false, isIntroduceSentenceRemoved: false });
|
2462
|
+
}
|
2463
|
+
else {
|
2464
|
+
return processedText;
|
2465
|
+
}
|
2466
|
+
}
|
2467
|
+
/**
|
2468
|
+
* TODO: [🧠] Should this also unwrap the (parenthesis)
|
2469
|
+
*/
|
2470
|
+
|
2295
2471
|
/**
|
2296
2472
|
* Trims string from all 4 sides
|
2297
2473
|
*
|
@@ -2320,99 +2496,6 @@ function extractParameterNames(template) {
|
|
2320
2496
|
return parameterNames;
|
2321
2497
|
}
|
2322
2498
|
|
2323
|
-
/**
|
2324
|
-
* Function parseNumber will parse number from string
|
2325
|
-
*
|
2326
|
-
* Note: [🔂] This function is idempotent.
|
2327
|
-
* Unlike Number.parseInt, Number.parseFloat it will never ever result in NaN
|
2328
|
-
* Note: it also works only with decimal numbers
|
2329
|
-
*
|
2330
|
-
* @returns parsed number
|
2331
|
-
* @throws {ParseError} if the value is not a number
|
2332
|
-
*
|
2333
|
-
* @public exported from `@promptbook/utils`
|
2334
|
-
*/
|
2335
|
-
function parseNumber(value) {
|
2336
|
-
const originalValue = value;
|
2337
|
-
if (typeof value === 'number') {
|
2338
|
-
value = value.toString(); // <- TODO: Maybe more efficient way to do this
|
2339
|
-
}
|
2340
|
-
if (typeof value !== 'string') {
|
2341
|
-
return 0;
|
2342
|
-
}
|
2343
|
-
value = value.trim();
|
2344
|
-
if (value.startsWith('+')) {
|
2345
|
-
return parseNumber(value.substring(1));
|
2346
|
-
}
|
2347
|
-
if (value.startsWith('-')) {
|
2348
|
-
const number = parseNumber(value.substring(1));
|
2349
|
-
if (number === 0) {
|
2350
|
-
return 0; // <- Note: To prevent -0
|
2351
|
-
}
|
2352
|
-
return -number;
|
2353
|
-
}
|
2354
|
-
value = value.replace(/,/g, '.');
|
2355
|
-
value = value.toUpperCase();
|
2356
|
-
if (value === '') {
|
2357
|
-
return 0;
|
2358
|
-
}
|
2359
|
-
if (value === '♾' || value.startsWith('INF')) {
|
2360
|
-
return Infinity;
|
2361
|
-
}
|
2362
|
-
if (value.includes('/')) {
|
2363
|
-
const [numerator_, denominator_] = value.split('/');
|
2364
|
-
const numerator = parseNumber(numerator_);
|
2365
|
-
const denominator = parseNumber(denominator_);
|
2366
|
-
if (denominator === 0) {
|
2367
|
-
throw new ParseError(`Unable to parse number from "${originalValue}" because denominator is zero`);
|
2368
|
-
}
|
2369
|
-
return numerator / denominator;
|
2370
|
-
}
|
2371
|
-
if (/^(NAN|NULL|NONE|UNDEFINED|ZERO|NO.*)$/.test(value)) {
|
2372
|
-
return 0;
|
2373
|
-
}
|
2374
|
-
if (value.includes('E')) {
|
2375
|
-
const [significand, exponent] = value.split('E');
|
2376
|
-
return parseNumber(significand) * 10 ** parseNumber(exponent);
|
2377
|
-
}
|
2378
|
-
if (!/^[0-9.]+$/.test(value) || value.split('.').length > 2) {
|
2379
|
-
throw new ParseError(`Unable to parse number from "${originalValue}"`);
|
2380
|
-
}
|
2381
|
-
const num = parseFloat(value);
|
2382
|
-
if (isNaN(num)) {
|
2383
|
-
throw new ParseError(`Unexpected NaN when parsing number from "${originalValue}"`);
|
2384
|
-
}
|
2385
|
-
return num;
|
2386
|
-
}
|
2387
|
-
/**
|
2388
|
-
* TODO: Maybe use sth. like safe-eval in fraction/calculation case @see https://www.npmjs.com/package/safe-eval
|
2389
|
-
* TODO: [🧠][🌻] Maybe export through `@promptbook/markdown-utils` not `@promptbook/utils`
|
2390
|
-
*/
|
2391
|
-
|
2392
|
-
/**
|
2393
|
-
* Removes quotes from a string
|
2394
|
-
*
|
2395
|
-
* Note: [🔂] This function is idempotent.
|
2396
|
-
* Tip: This is very useful for post-processing of the result of the LLM model
|
2397
|
-
* Note: This function removes only the same quotes from the beginning and the end of the string
|
2398
|
-
* Note: There are two similar functions:
|
2399
|
-
* - `removeQuotes` which removes only bounding quotes
|
2400
|
-
* - `unwrapResult` which removes whole introduce sentence
|
2401
|
-
*
|
2402
|
-
* @param text optionally quoted text
|
2403
|
-
* @returns text without quotes
|
2404
|
-
* @public exported from `@promptbook/utils`
|
2405
|
-
*/
|
2406
|
-
function removeQuotes(text) {
|
2407
|
-
if (text.startsWith('"') && text.endsWith('"')) {
|
2408
|
-
return text.slice(1, -1);
|
2409
|
-
}
|
2410
|
-
if (text.startsWith("'") && text.endsWith("'")) {
|
2411
|
-
return text.slice(1, -1);
|
2412
|
-
}
|
2413
|
-
return text;
|
2414
|
-
}
|
2415
|
-
|
2416
2499
|
/**
|
2417
2500
|
* Creates a deep clone of a PipelineJson object, copying all properties explicitly.
|
2418
2501
|
*
|
@@ -2569,112 +2652,6 @@ function union(...sets) {
|
|
2569
2652
|
return union;
|
2570
2653
|
}
|
2571
2654
|
|
2572
|
-
/**
|
2573
|
-
* Function trimCodeBlock will trim starting and ending code block from the string if it is present.
|
2574
|
-
*
|
2575
|
-
* Note: [🔂] This function is idempotent.
|
2576
|
-
* Note: This is useful for post-processing of the result of the chat LLM model
|
2577
|
-
* when the model wraps the result in the (markdown) code block.
|
2578
|
-
*
|
2579
|
-
* @public exported from `@promptbook/utils`
|
2580
|
-
*/
|
2581
|
-
function trimCodeBlock(value) {
|
2582
|
-
value = spaceTrim$2(value);
|
2583
|
-
if (!/^```[a-z]*(.*)```$/is.test(value)) {
|
2584
|
-
return value;
|
2585
|
-
}
|
2586
|
-
value = value.replace(/^```[a-z]*/i, '');
|
2587
|
-
value = value.replace(/```$/i, '');
|
2588
|
-
value = spaceTrim$2(value);
|
2589
|
-
return value;
|
2590
|
-
}
|
2591
|
-
|
2592
|
-
/**
|
2593
|
-
* Function trimEndOfCodeBlock will remove ending code block from the string if it is present.
|
2594
|
-
*
|
2595
|
-
* Note: This is useful for post-processing of the result of the completion LLM model
|
2596
|
-
* if you want to start code block in the prompt but you don't want to end it in the result.
|
2597
|
-
*
|
2598
|
-
* @public exported from `@promptbook/utils`
|
2599
|
-
*/
|
2600
|
-
function trimEndOfCodeBlock(value) {
|
2601
|
-
value = spaceTrim$2(value);
|
2602
|
-
value = value.replace(/```$/g, '');
|
2603
|
-
value = spaceTrim$2(value);
|
2604
|
-
return value;
|
2605
|
-
}
|
2606
|
-
|
2607
|
-
/**
|
2608
|
-
* Removes quotes and optional introduce text from a string
|
2609
|
-
*
|
2610
|
-
* Tip: This is very useful for post-processing of the result of the LLM model
|
2611
|
-
* Note: This function trims the text and removes whole introduce sentence if it is present
|
2612
|
-
* Note: There are two similar functions:
|
2613
|
-
* - `removeQuotes` which removes only bounding quotes
|
2614
|
-
* - `unwrapResult` which removes whole introduce sentence
|
2615
|
-
*
|
2616
|
-
* @param text optionally quoted text
|
2617
|
-
* @returns text without quotes
|
2618
|
-
* @public exported from `@promptbook/utils`
|
2619
|
-
*/
|
2620
|
-
function unwrapResult(text, options) {
|
2621
|
-
const { isTrimmed = true, isIntroduceSentenceRemoved = true } = options || {};
|
2622
|
-
let trimmedText = text;
|
2623
|
-
// Remove leading and trailing spaces and newlines
|
2624
|
-
if (isTrimmed) {
|
2625
|
-
trimmedText = spaceTrim$2(trimmedText);
|
2626
|
-
}
|
2627
|
-
let processedText = trimmedText;
|
2628
|
-
if (isIntroduceSentenceRemoved) {
|
2629
|
-
const introduceSentenceRegex = /^[a-zěščřžýáíéúů:\s]*:\s*/i;
|
2630
|
-
if (introduceSentenceRegex.test(text)) {
|
2631
|
-
// Remove the introduce sentence and quotes by replacing it with an empty string
|
2632
|
-
processedText = processedText.replace(introduceSentenceRegex, '');
|
2633
|
-
}
|
2634
|
-
processedText = spaceTrim$2(processedText);
|
2635
|
-
}
|
2636
|
-
if (processedText.length < 3) {
|
2637
|
-
return trimmedText;
|
2638
|
-
}
|
2639
|
-
if (processedText.includes('\n')) {
|
2640
|
-
return trimmedText;
|
2641
|
-
}
|
2642
|
-
// Remove the quotes by extracting the substring without the first and last characters
|
2643
|
-
const unquotedText = processedText.slice(1, -1);
|
2644
|
-
// Check if the text starts and ends with quotes
|
2645
|
-
if ([
|
2646
|
-
['"', '"'],
|
2647
|
-
["'", "'"],
|
2648
|
-
['`', '`'],
|
2649
|
-
['*', '*'],
|
2650
|
-
['_', '_'],
|
2651
|
-
['„', '“'],
|
2652
|
-
['«', '»'] /* <- QUOTES to config */,
|
2653
|
-
].some(([startQuote, endQuote]) => {
|
2654
|
-
if (!processedText.startsWith(startQuote)) {
|
2655
|
-
return false;
|
2656
|
-
}
|
2657
|
-
if (!processedText.endsWith(endQuote)) {
|
2658
|
-
return false;
|
2659
|
-
}
|
2660
|
-
if (unquotedText.includes(startQuote) && !unquotedText.includes(endQuote)) {
|
2661
|
-
return false;
|
2662
|
-
}
|
2663
|
-
if (!unquotedText.includes(startQuote) && unquotedText.includes(endQuote)) {
|
2664
|
-
return false;
|
2665
|
-
}
|
2666
|
-
return true;
|
2667
|
-
})) {
|
2668
|
-
return unwrapResult(unquotedText, { isTrimmed: false, isIntroduceSentenceRemoved: false });
|
2669
|
-
}
|
2670
|
-
else {
|
2671
|
-
return processedText;
|
2672
|
-
}
|
2673
|
-
}
|
2674
|
-
/**
|
2675
|
-
* TODO: [🧠] Should this also unwrap the (parenthesis)
|
2676
|
-
*/
|
2677
|
-
|
2678
2655
|
/**
|
2679
2656
|
* Checks if value is valid email
|
2680
2657
|
*
|
@@ -2862,5 +2839,5 @@ function isValidUuid(value) {
|
|
2862
2839
|
return /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i.test(value);
|
2863
2840
|
}
|
2864
2841
|
|
2865
|
-
export { $deepFreeze, $getCurrentDate, $isRunningInBrowser, $isRunningInJest, $isRunningInNode, $isRunningInWebWorker, BOOK_LANGUAGE_VERSION, CHARACTERS_PER_STANDARD_LINE, CountUtils, DIACRITIC_VARIANTS_LETTERS, LINES_PER_STANDARD_PAGE, PROMPTBOOK_ENGINE_VERSION, SMALL_NUMBER, VALUE_STRINGS, capitalize, checkSerializableAsJson, clonePipeline, countCharacters, countLines, countPages, countParagraphs, countSentences, countWords, decapitalize, deepClone, deserializeError, difference, exportJson, extractParameterNames, forEachAsync, intersection, isHostnameOnPrivateNetwork, isRootPath, isSerializableAsJson, isUrlOnPrivateNetwork, isValidCsvString, isValidEmail, isValidFilePath, isValidJavascriptName, isValidJsonString, isValidKeyword, isValidPipelineUrl, isValidPromptbookVersion, isValidSemanticVersion, isValidUrl, isValidUuid, isValidXmlString, jsonParse, jsonStringsToJsons, nameToUriPart, nameToUriParts, normalizeToKebabCase, normalizeTo_PascalCase, normalizeTo_SCREAMING_CASE, normalizeTo_camelCase, normalizeTo_snake_case, normalizeWhitespaces, numberToString, orderJson, parseKeywords, parseKeywordsFromString, parseNumber, prompt, promptTemplate, removeDiacritics, removeEmojis, removeQuotes, renderPromptbookMermaid, searchKeywords, serializeError, spaceTrim, splitIntoSentences, suffixUrl, templateParameters, titleToName,
|
2842
|
+
export { $deepFreeze, $getCurrentDate, $isRunningInBrowser, $isRunningInJest, $isRunningInNode, $isRunningInWebWorker, BOOK_LANGUAGE_VERSION, CHARACTERS_PER_STANDARD_LINE, CountUtils, DIACRITIC_VARIANTS_LETTERS, LINES_PER_STANDARD_PAGE, PROMPTBOOK_ENGINE_VERSION, SMALL_NUMBER, VALUE_STRINGS, capitalize, checkSerializableAsJson, clonePipeline, countCharacters, countLines, countPages, countParagraphs, countSentences, countWords, debounce, decapitalize, deepClone, deserializeError, difference, exportJson, extractParameterNames, forEachAsync, intersection, isHostnameOnPrivateNetwork, isRootPath, isSerializableAsJson, isUrlOnPrivateNetwork, isValidCsvString, isValidEmail, isValidFilePath, isValidJavascriptName, isValidJsonString, isValidKeyword, isValidPipelineUrl, isValidPromptbookVersion, isValidSemanticVersion, isValidUrl, isValidUuid, isValidXmlString, jsonParse, jsonStringsToJsons, nameToUriPart, nameToUriParts, normalizeToKebabCase, normalizeTo_PascalCase, normalizeTo_SCREAMING_CASE, normalizeTo_camelCase, normalizeTo_snake_case, normalizeWhitespaces, numberToString, orderJson, parseKeywords, parseKeywordsFromString, parseNumber, prompt, promptTemplate, removeDiacritics, removeEmojis, removeQuotes, renderPromptbookMermaid, searchKeywords, serializeError, spaceTrim, splitIntoSentences, suffixUrl, templateParameters, titleToName, union, unwrapResult, valueToString };
|
2866
2843
|
//# sourceMappingURL=index.es.js.map
|