@promptbook/utils 0.102.0-5 → 0.102.0-7
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 +0 -4
- 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/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/book-components/BookEditor/utils.d.ts +0 -8
- /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
@@ -0,0 +1,20 @@
|
|
1
|
+
import type { string_css_class } from '../../types/typeAliases';
|
2
|
+
export type InjectCssModuleIntoShadowRootOptions = {
|
3
|
+
/**
|
4
|
+
* The shadow root where the styles should be injected
|
5
|
+
*/
|
6
|
+
shadowRoot: ShadowRoot;
|
7
|
+
/**
|
8
|
+
* The imported CSS module styles object
|
9
|
+
*/
|
10
|
+
styles: Record<string_css_class, string_css_class>;
|
11
|
+
};
|
12
|
+
/**
|
13
|
+
* Inject the CSS module rules (derived from imported `styles`) into the provided shadow root.
|
14
|
+
* This allows CSS modules (which are normally emitted into the document head) to be
|
15
|
+
* available inside the component's shadow DOM.
|
16
|
+
*
|
17
|
+
* @public exported from `@promptbook/components`
|
18
|
+
* <- TODO: [🧠] Make `@promptbook/components-utils`
|
19
|
+
*/
|
20
|
+
export declare function injectCssModuleIntoShadowRoot(options: InjectCssModuleIntoShadowRootOptions): void;
|
@@ -15,7 +15,7 @@ export declare const BOOK_LANGUAGE_VERSION: string_semantic_version;
|
|
15
15
|
export declare const PROMPTBOOK_ENGINE_VERSION: string_promptbook_version;
|
16
16
|
/**
|
17
17
|
* Represents the version string of the Promptbook engine.
|
18
|
-
* It follows semantic versioning (e.g., `0.102.0-
|
18
|
+
* It follows semantic versioning (e.g., `0.102.0-6`).
|
19
19
|
*
|
20
20
|
* @generated
|
21
21
|
*/
|
package/package.json
CHANGED
package/umd/index.umd.js
CHANGED
@@ -22,7 +22,7 @@
|
|
22
22
|
* @generated
|
23
23
|
* @see https://github.com/webgptorg/promptbook
|
24
24
|
*/
|
25
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.102.0-
|
25
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.102.0-7';
|
26
26
|
/**
|
27
27
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
28
28
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
@@ -552,24 +552,6 @@
|
|
552
552
|
* TODO: [🌺] Use some intermediate util splitWords
|
553
553
|
*/
|
554
554
|
|
555
|
-
/**
|
556
|
-
* Removes emojis from a string and fix whitespaces
|
557
|
-
*
|
558
|
-
* Note: [🔂] This function is idempotent.
|
559
|
-
*
|
560
|
-
* @param text with emojis
|
561
|
-
* @returns text without emojis
|
562
|
-
* @public exported from `@promptbook/utils`
|
563
|
-
*/
|
564
|
-
function removeEmojis(text) {
|
565
|
-
// Replace emojis (and also ZWJ sequence) with hyphens
|
566
|
-
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
567
|
-
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
568
|
-
text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
|
569
|
-
text = text.replace(/\p{Extended_Pictographic}/gu, '');
|
570
|
-
return text;
|
571
|
-
}
|
572
|
-
|
573
555
|
/**
|
574
556
|
* Tests if given string is valid file path.
|
575
557
|
*
|
@@ -970,6 +952,24 @@
|
|
970
952
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
971
953
|
*/
|
972
954
|
|
955
|
+
/**
|
956
|
+
* Removes emojis from a string and fix whitespaces
|
957
|
+
*
|
958
|
+
* Note: [🔂] This function is idempotent.
|
959
|
+
*
|
960
|
+
* @param text with emojis
|
961
|
+
* @returns text without emojis
|
962
|
+
* @public exported from `@promptbook/utils`
|
963
|
+
*/
|
964
|
+
function removeEmojis(text) {
|
965
|
+
// Replace emojis (and also ZWJ sequence) with hyphens
|
966
|
+
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
967
|
+
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
968
|
+
text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
|
969
|
+
text = text.replace(/\p{Extended_Pictographic}/gu, '');
|
970
|
+
return text;
|
971
|
+
}
|
972
|
+
|
973
973
|
/**
|
974
974
|
* Converts a title string into a normalized name.
|
975
975
|
*
|
@@ -1825,18 +1825,6 @@
|
|
1825
1825
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
1826
1826
|
*/
|
1827
1827
|
|
1828
|
-
/**
|
1829
|
-
* Simple wrapper `new Date().toISOString()`
|
1830
|
-
*
|
1831
|
-
* Note: `$` is used to indicate that this function is not a pure function - it is not deterministic because it depends on the current time
|
1832
|
-
*
|
1833
|
-
* @returns string_date branded type
|
1834
|
-
* @public exported from `@promptbook/utils`
|
1835
|
-
*/
|
1836
|
-
function $getCurrentDate() {
|
1837
|
-
return new Date().toISOString();
|
1838
|
-
}
|
1839
|
-
|
1840
1828
|
/**
|
1841
1829
|
* Detects if the code is running in a browser environment in main thread (Not in a web worker)
|
1842
1830
|
*
|
@@ -2052,6 +2040,99 @@
|
|
2052
2040
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
2053
2041
|
*/
|
2054
2042
|
|
2043
|
+
/**
|
2044
|
+
* Simple wrapper `new Date().toISOString()`
|
2045
|
+
*
|
2046
|
+
* Note: `$` is used to indicate that this function is not a pure function - it is not deterministic because it depends on the current time
|
2047
|
+
*
|
2048
|
+
* @returns string_date branded type
|
2049
|
+
* @public exported from `@promptbook/utils`
|
2050
|
+
*/
|
2051
|
+
function $getCurrentDate() {
|
2052
|
+
return new Date().toISOString();
|
2053
|
+
}
|
2054
|
+
|
2055
|
+
/**
|
2056
|
+
* @public exported from `@promptbook/utils`
|
2057
|
+
*/
|
2058
|
+
function debounce(fn, delay) {
|
2059
|
+
let timeout = null;
|
2060
|
+
return (...args) => {
|
2061
|
+
if (timeout)
|
2062
|
+
clearTimeout(timeout);
|
2063
|
+
timeout = setTimeout(() => fn(...args), delay);
|
2064
|
+
};
|
2065
|
+
}
|
2066
|
+
|
2067
|
+
/**
|
2068
|
+
* Function parseNumber will parse number from string
|
2069
|
+
*
|
2070
|
+
* Note: [🔂] This function is idempotent.
|
2071
|
+
* Unlike Number.parseInt, Number.parseFloat it will never ever result in NaN
|
2072
|
+
* Note: it also works only with decimal numbers
|
2073
|
+
*
|
2074
|
+
* @returns parsed number
|
2075
|
+
* @throws {ParseError} if the value is not a number
|
2076
|
+
*
|
2077
|
+
* @public exported from `@promptbook/utils`
|
2078
|
+
*/
|
2079
|
+
function parseNumber(value) {
|
2080
|
+
const originalValue = value;
|
2081
|
+
if (typeof value === 'number') {
|
2082
|
+
value = value.toString(); // <- TODO: Maybe more efficient way to do this
|
2083
|
+
}
|
2084
|
+
if (typeof value !== 'string') {
|
2085
|
+
return 0;
|
2086
|
+
}
|
2087
|
+
value = value.trim();
|
2088
|
+
if (value.startsWith('+')) {
|
2089
|
+
return parseNumber(value.substring(1));
|
2090
|
+
}
|
2091
|
+
if (value.startsWith('-')) {
|
2092
|
+
const number = parseNumber(value.substring(1));
|
2093
|
+
if (number === 0) {
|
2094
|
+
return 0; // <- Note: To prevent -0
|
2095
|
+
}
|
2096
|
+
return -number;
|
2097
|
+
}
|
2098
|
+
value = value.replace(/,/g, '.');
|
2099
|
+
value = value.toUpperCase();
|
2100
|
+
if (value === '') {
|
2101
|
+
return 0;
|
2102
|
+
}
|
2103
|
+
if (value === '♾' || value.startsWith('INF')) {
|
2104
|
+
return Infinity;
|
2105
|
+
}
|
2106
|
+
if (value.includes('/')) {
|
2107
|
+
const [numerator_, denominator_] = value.split('/');
|
2108
|
+
const numerator = parseNumber(numerator_);
|
2109
|
+
const denominator = parseNumber(denominator_);
|
2110
|
+
if (denominator === 0) {
|
2111
|
+
throw new ParseError(`Unable to parse number from "${originalValue}" because denominator is zero`);
|
2112
|
+
}
|
2113
|
+
return numerator / denominator;
|
2114
|
+
}
|
2115
|
+
if (/^(NAN|NULL|NONE|UNDEFINED|ZERO|NO.*)$/.test(value)) {
|
2116
|
+
return 0;
|
2117
|
+
}
|
2118
|
+
if (value.includes('E')) {
|
2119
|
+
const [significand, exponent] = value.split('E');
|
2120
|
+
return parseNumber(significand) * 10 ** parseNumber(exponent);
|
2121
|
+
}
|
2122
|
+
if (!/^[0-9.]+$/.test(value) || value.split('.').length > 2) {
|
2123
|
+
throw new ParseError(`Unable to parse number from "${originalValue}"`);
|
2124
|
+
}
|
2125
|
+
const num = parseFloat(value);
|
2126
|
+
if (isNaN(num)) {
|
2127
|
+
throw new ParseError(`Unexpected NaN when parsing number from "${originalValue}"`);
|
2128
|
+
}
|
2129
|
+
return num;
|
2130
|
+
}
|
2131
|
+
/**
|
2132
|
+
* TODO: Maybe use sth. like safe-eval in fraction/calculation case @see https://www.npmjs.com/package/safe-eval
|
2133
|
+
* TODO: [🧠][🌻] Maybe export through `@promptbook/markdown-utils` not `@promptbook/utils`
|
2134
|
+
*/
|
2135
|
+
|
2055
2136
|
/**
|
2056
2137
|
* Makes first letter of a string uppercase
|
2057
2138
|
*
|
@@ -2267,6 +2348,30 @@
|
|
2267
2348
|
* TODO: [🌺] Use some intermediate util splitWords
|
2268
2349
|
*/
|
2269
2350
|
|
2351
|
+
/**
|
2352
|
+
* Removes quotes from a string
|
2353
|
+
*
|
2354
|
+
* Note: [🔂] This function is idempotent.
|
2355
|
+
* Tip: This is very useful for post-processing of the result of the LLM model
|
2356
|
+
* Note: This function removes only the same quotes from the beginning and the end of the string
|
2357
|
+
* Note: There are two similar functions:
|
2358
|
+
* - `removeQuotes` which removes only bounding quotes
|
2359
|
+
* - `unwrapResult` which removes whole introduce sentence
|
2360
|
+
*
|
2361
|
+
* @param text optionally quoted text
|
2362
|
+
* @returns text without quotes
|
2363
|
+
* @public exported from `@promptbook/utils`
|
2364
|
+
*/
|
2365
|
+
function removeQuotes(text) {
|
2366
|
+
if (text.startsWith('"') && text.endsWith('"')) {
|
2367
|
+
return text.slice(1, -1);
|
2368
|
+
}
|
2369
|
+
if (text.startsWith("'") && text.endsWith("'")) {
|
2370
|
+
return text.slice(1, -1);
|
2371
|
+
}
|
2372
|
+
return text;
|
2373
|
+
}
|
2374
|
+
|
2270
2375
|
/**
|
2271
2376
|
* Searches set of keywords for a specific keyword
|
2272
2377
|
*
|
@@ -2298,6 +2403,77 @@
|
|
2298
2403
|
return (baseUrl + normalizedSuffix);
|
2299
2404
|
}
|
2300
2405
|
|
2406
|
+
/**
|
2407
|
+
* Removes quotes and optional introduce text from a string
|
2408
|
+
*
|
2409
|
+
* Tip: This is very useful for post-processing of the result of the LLM model
|
2410
|
+
* Note: This function trims the text and removes whole introduce sentence if it is present
|
2411
|
+
* Note: There are two similar functions:
|
2412
|
+
* - `removeQuotes` which removes only bounding quotes
|
2413
|
+
* - `unwrapResult` which removes whole introduce sentence
|
2414
|
+
*
|
2415
|
+
* @param text optionally quoted text
|
2416
|
+
* @returns text without quotes
|
2417
|
+
* @public exported from `@promptbook/utils`
|
2418
|
+
*/
|
2419
|
+
function unwrapResult(text, options) {
|
2420
|
+
const { isTrimmed = true, isIntroduceSentenceRemoved = true } = options || {};
|
2421
|
+
let trimmedText = text;
|
2422
|
+
// Remove leading and trailing spaces and newlines
|
2423
|
+
if (isTrimmed) {
|
2424
|
+
trimmedText = spaceTrim$1.spaceTrim(trimmedText);
|
2425
|
+
}
|
2426
|
+
let processedText = trimmedText;
|
2427
|
+
if (isIntroduceSentenceRemoved) {
|
2428
|
+
const introduceSentenceRegex = /^[a-zěščřžýáíéúů:\s]*:\s*/i;
|
2429
|
+
if (introduceSentenceRegex.test(text)) {
|
2430
|
+
// Remove the introduce sentence and quotes by replacing it with an empty string
|
2431
|
+
processedText = processedText.replace(introduceSentenceRegex, '');
|
2432
|
+
}
|
2433
|
+
processedText = spaceTrim$1.spaceTrim(processedText);
|
2434
|
+
}
|
2435
|
+
if (processedText.length < 3) {
|
2436
|
+
return trimmedText;
|
2437
|
+
}
|
2438
|
+
if (processedText.includes('\n')) {
|
2439
|
+
return trimmedText;
|
2440
|
+
}
|
2441
|
+
// Remove the quotes by extracting the substring without the first and last characters
|
2442
|
+
const unquotedText = processedText.slice(1, -1);
|
2443
|
+
// Check if the text starts and ends with quotes
|
2444
|
+
if ([
|
2445
|
+
['"', '"'],
|
2446
|
+
["'", "'"],
|
2447
|
+
['`', '`'],
|
2448
|
+
['*', '*'],
|
2449
|
+
['_', '_'],
|
2450
|
+
['„', '“'],
|
2451
|
+
['«', '»'] /* <- QUOTES to config */,
|
2452
|
+
].some(([startQuote, endQuote]) => {
|
2453
|
+
if (!processedText.startsWith(startQuote)) {
|
2454
|
+
return false;
|
2455
|
+
}
|
2456
|
+
if (!processedText.endsWith(endQuote)) {
|
2457
|
+
return false;
|
2458
|
+
}
|
2459
|
+
if (unquotedText.includes(startQuote) && !unquotedText.includes(endQuote)) {
|
2460
|
+
return false;
|
2461
|
+
}
|
2462
|
+
if (!unquotedText.includes(startQuote) && unquotedText.includes(endQuote)) {
|
2463
|
+
return false;
|
2464
|
+
}
|
2465
|
+
return true;
|
2466
|
+
})) {
|
2467
|
+
return unwrapResult(unquotedText, { isTrimmed: false, isIntroduceSentenceRemoved: false });
|
2468
|
+
}
|
2469
|
+
else {
|
2470
|
+
return processedText;
|
2471
|
+
}
|
2472
|
+
}
|
2473
|
+
/**
|
2474
|
+
* TODO: [🧠] Should this also unwrap the (parenthesis)
|
2475
|
+
*/
|
2476
|
+
|
2301
2477
|
/**
|
2302
2478
|
* Trims string from all 4 sides
|
2303
2479
|
*
|
@@ -2326,99 +2502,6 @@
|
|
2326
2502
|
return parameterNames;
|
2327
2503
|
}
|
2328
2504
|
|
2329
|
-
/**
|
2330
|
-
* Function parseNumber will parse number from string
|
2331
|
-
*
|
2332
|
-
* Note: [🔂] This function is idempotent.
|
2333
|
-
* Unlike Number.parseInt, Number.parseFloat it will never ever result in NaN
|
2334
|
-
* Note: it also works only with decimal numbers
|
2335
|
-
*
|
2336
|
-
* @returns parsed number
|
2337
|
-
* @throws {ParseError} if the value is not a number
|
2338
|
-
*
|
2339
|
-
* @public exported from `@promptbook/utils`
|
2340
|
-
*/
|
2341
|
-
function parseNumber(value) {
|
2342
|
-
const originalValue = value;
|
2343
|
-
if (typeof value === 'number') {
|
2344
|
-
value = value.toString(); // <- TODO: Maybe more efficient way to do this
|
2345
|
-
}
|
2346
|
-
if (typeof value !== 'string') {
|
2347
|
-
return 0;
|
2348
|
-
}
|
2349
|
-
value = value.trim();
|
2350
|
-
if (value.startsWith('+')) {
|
2351
|
-
return parseNumber(value.substring(1));
|
2352
|
-
}
|
2353
|
-
if (value.startsWith('-')) {
|
2354
|
-
const number = parseNumber(value.substring(1));
|
2355
|
-
if (number === 0) {
|
2356
|
-
return 0; // <- Note: To prevent -0
|
2357
|
-
}
|
2358
|
-
return -number;
|
2359
|
-
}
|
2360
|
-
value = value.replace(/,/g, '.');
|
2361
|
-
value = value.toUpperCase();
|
2362
|
-
if (value === '') {
|
2363
|
-
return 0;
|
2364
|
-
}
|
2365
|
-
if (value === '♾' || value.startsWith('INF')) {
|
2366
|
-
return Infinity;
|
2367
|
-
}
|
2368
|
-
if (value.includes('/')) {
|
2369
|
-
const [numerator_, denominator_] = value.split('/');
|
2370
|
-
const numerator = parseNumber(numerator_);
|
2371
|
-
const denominator = parseNumber(denominator_);
|
2372
|
-
if (denominator === 0) {
|
2373
|
-
throw new ParseError(`Unable to parse number from "${originalValue}" because denominator is zero`);
|
2374
|
-
}
|
2375
|
-
return numerator / denominator;
|
2376
|
-
}
|
2377
|
-
if (/^(NAN|NULL|NONE|UNDEFINED|ZERO|NO.*)$/.test(value)) {
|
2378
|
-
return 0;
|
2379
|
-
}
|
2380
|
-
if (value.includes('E')) {
|
2381
|
-
const [significand, exponent] = value.split('E');
|
2382
|
-
return parseNumber(significand) * 10 ** parseNumber(exponent);
|
2383
|
-
}
|
2384
|
-
if (!/^[0-9.]+$/.test(value) || value.split('.').length > 2) {
|
2385
|
-
throw new ParseError(`Unable to parse number from "${originalValue}"`);
|
2386
|
-
}
|
2387
|
-
const num = parseFloat(value);
|
2388
|
-
if (isNaN(num)) {
|
2389
|
-
throw new ParseError(`Unexpected NaN when parsing number from "${originalValue}"`);
|
2390
|
-
}
|
2391
|
-
return num;
|
2392
|
-
}
|
2393
|
-
/**
|
2394
|
-
* TODO: Maybe use sth. like safe-eval in fraction/calculation case @see https://www.npmjs.com/package/safe-eval
|
2395
|
-
* TODO: [🧠][🌻] Maybe export through `@promptbook/markdown-utils` not `@promptbook/utils`
|
2396
|
-
*/
|
2397
|
-
|
2398
|
-
/**
|
2399
|
-
* Removes quotes from a string
|
2400
|
-
*
|
2401
|
-
* Note: [🔂] This function is idempotent.
|
2402
|
-
* Tip: This is very useful for post-processing of the result of the LLM model
|
2403
|
-
* Note: This function removes only the same quotes from the beginning and the end of the string
|
2404
|
-
* Note: There are two similar functions:
|
2405
|
-
* - `removeQuotes` which removes only bounding quotes
|
2406
|
-
* - `unwrapResult` which removes whole introduce sentence
|
2407
|
-
*
|
2408
|
-
* @param text optionally quoted text
|
2409
|
-
* @returns text without quotes
|
2410
|
-
* @public exported from `@promptbook/utils`
|
2411
|
-
*/
|
2412
|
-
function removeQuotes(text) {
|
2413
|
-
if (text.startsWith('"') && text.endsWith('"')) {
|
2414
|
-
return text.slice(1, -1);
|
2415
|
-
}
|
2416
|
-
if (text.startsWith("'") && text.endsWith("'")) {
|
2417
|
-
return text.slice(1, -1);
|
2418
|
-
}
|
2419
|
-
return text;
|
2420
|
-
}
|
2421
|
-
|
2422
2505
|
/**
|
2423
2506
|
* Creates a deep clone of a PipelineJson object, copying all properties explicitly.
|
2424
2507
|
*
|
@@ -2575,112 +2658,6 @@
|
|
2575
2658
|
return union;
|
2576
2659
|
}
|
2577
2660
|
|
2578
|
-
/**
|
2579
|
-
* Function trimCodeBlock will trim starting and ending code block from the string if it is present.
|
2580
|
-
*
|
2581
|
-
* Note: [🔂] This function is idempotent.
|
2582
|
-
* Note: This is useful for post-processing of the result of the chat LLM model
|
2583
|
-
* when the model wraps the result in the (markdown) code block.
|
2584
|
-
*
|
2585
|
-
* @public exported from `@promptbook/utils`
|
2586
|
-
*/
|
2587
|
-
function trimCodeBlock(value) {
|
2588
|
-
value = spaceTrim$1.spaceTrim(value);
|
2589
|
-
if (!/^```[a-z]*(.*)```$/is.test(value)) {
|
2590
|
-
return value;
|
2591
|
-
}
|
2592
|
-
value = value.replace(/^```[a-z]*/i, '');
|
2593
|
-
value = value.replace(/```$/i, '');
|
2594
|
-
value = spaceTrim$1.spaceTrim(value);
|
2595
|
-
return value;
|
2596
|
-
}
|
2597
|
-
|
2598
|
-
/**
|
2599
|
-
* Function trimEndOfCodeBlock will remove ending code block from the string if it is present.
|
2600
|
-
*
|
2601
|
-
* Note: This is useful for post-processing of the result of the completion LLM model
|
2602
|
-
* if you want to start code block in the prompt but you don't want to end it in the result.
|
2603
|
-
*
|
2604
|
-
* @public exported from `@promptbook/utils`
|
2605
|
-
*/
|
2606
|
-
function trimEndOfCodeBlock(value) {
|
2607
|
-
value = spaceTrim$1.spaceTrim(value);
|
2608
|
-
value = value.replace(/```$/g, '');
|
2609
|
-
value = spaceTrim$1.spaceTrim(value);
|
2610
|
-
return value;
|
2611
|
-
}
|
2612
|
-
|
2613
|
-
/**
|
2614
|
-
* Removes quotes and optional introduce text from a string
|
2615
|
-
*
|
2616
|
-
* Tip: This is very useful for post-processing of the result of the LLM model
|
2617
|
-
* Note: This function trims the text and removes whole introduce sentence if it is present
|
2618
|
-
* Note: There are two similar functions:
|
2619
|
-
* - `removeQuotes` which removes only bounding quotes
|
2620
|
-
* - `unwrapResult` which removes whole introduce sentence
|
2621
|
-
*
|
2622
|
-
* @param text optionally quoted text
|
2623
|
-
* @returns text without quotes
|
2624
|
-
* @public exported from `@promptbook/utils`
|
2625
|
-
*/
|
2626
|
-
function unwrapResult(text, options) {
|
2627
|
-
const { isTrimmed = true, isIntroduceSentenceRemoved = true } = options || {};
|
2628
|
-
let trimmedText = text;
|
2629
|
-
// Remove leading and trailing spaces and newlines
|
2630
|
-
if (isTrimmed) {
|
2631
|
-
trimmedText = spaceTrim$1.spaceTrim(trimmedText);
|
2632
|
-
}
|
2633
|
-
let processedText = trimmedText;
|
2634
|
-
if (isIntroduceSentenceRemoved) {
|
2635
|
-
const introduceSentenceRegex = /^[a-zěščřžýáíéúů:\s]*:\s*/i;
|
2636
|
-
if (introduceSentenceRegex.test(text)) {
|
2637
|
-
// Remove the introduce sentence and quotes by replacing it with an empty string
|
2638
|
-
processedText = processedText.replace(introduceSentenceRegex, '');
|
2639
|
-
}
|
2640
|
-
processedText = spaceTrim$1.spaceTrim(processedText);
|
2641
|
-
}
|
2642
|
-
if (processedText.length < 3) {
|
2643
|
-
return trimmedText;
|
2644
|
-
}
|
2645
|
-
if (processedText.includes('\n')) {
|
2646
|
-
return trimmedText;
|
2647
|
-
}
|
2648
|
-
// Remove the quotes by extracting the substring without the first and last characters
|
2649
|
-
const unquotedText = processedText.slice(1, -1);
|
2650
|
-
// Check if the text starts and ends with quotes
|
2651
|
-
if ([
|
2652
|
-
['"', '"'],
|
2653
|
-
["'", "'"],
|
2654
|
-
['`', '`'],
|
2655
|
-
['*', '*'],
|
2656
|
-
['_', '_'],
|
2657
|
-
['„', '“'],
|
2658
|
-
['«', '»'] /* <- QUOTES to config */,
|
2659
|
-
].some(([startQuote, endQuote]) => {
|
2660
|
-
if (!processedText.startsWith(startQuote)) {
|
2661
|
-
return false;
|
2662
|
-
}
|
2663
|
-
if (!processedText.endsWith(endQuote)) {
|
2664
|
-
return false;
|
2665
|
-
}
|
2666
|
-
if (unquotedText.includes(startQuote) && !unquotedText.includes(endQuote)) {
|
2667
|
-
return false;
|
2668
|
-
}
|
2669
|
-
if (!unquotedText.includes(startQuote) && unquotedText.includes(endQuote)) {
|
2670
|
-
return false;
|
2671
|
-
}
|
2672
|
-
return true;
|
2673
|
-
})) {
|
2674
|
-
return unwrapResult(unquotedText, { isTrimmed: false, isIntroduceSentenceRemoved: false });
|
2675
|
-
}
|
2676
|
-
else {
|
2677
|
-
return processedText;
|
2678
|
-
}
|
2679
|
-
}
|
2680
|
-
/**
|
2681
|
-
* TODO: [🧠] Should this also unwrap the (parenthesis)
|
2682
|
-
*/
|
2683
|
-
|
2684
2661
|
/**
|
2685
2662
|
* Checks if value is valid email
|
2686
2663
|
*
|
@@ -2891,6 +2868,7 @@
|
|
2891
2868
|
exports.countParagraphs = countParagraphs;
|
2892
2869
|
exports.countSentences = countSentences;
|
2893
2870
|
exports.countWords = countWords;
|
2871
|
+
exports.debounce = debounce;
|
2894
2872
|
exports.decapitalize = decapitalize;
|
2895
2873
|
exports.deepClone = deepClone;
|
2896
2874
|
exports.deserializeError = deserializeError;
|
@@ -2943,8 +2921,6 @@
|
|
2943
2921
|
exports.suffixUrl = suffixUrl;
|
2944
2922
|
exports.templateParameters = templateParameters;
|
2945
2923
|
exports.titleToName = titleToName;
|
2946
|
-
exports.trimCodeBlock = trimCodeBlock;
|
2947
|
-
exports.trimEndOfCodeBlock = trimEndOfCodeBlock;
|
2948
2924
|
exports.union = union;
|
2949
2925
|
exports.unwrapResult = unwrapResult;
|
2950
2926
|
exports.valueToString = valueToString;
|