@promptbook/utils 0.101.0-0 → 0.101.0-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +124 -8
- package/esm/index.es.js +23 -2
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/components.index.d.ts +12 -0
- package/esm/typings/src/book-components/Chat/Chat/Chat.d.ts +0 -5
- package/esm/typings/src/book-components/Chat/Chat/ChatProps.d.ts +8 -2
- package/esm/typings/src/book-components/Chat/Chat/constants.d.ts +8 -0
- package/esm/typings/src/book-components/Chat/examples/ChatMarkdownDemo.d.ts +16 -0
- package/esm/typings/src/book-components/Chat/utils/renderMarkdown.d.ts +21 -0
- package/esm/typings/src/book-components/Chat/utils/renderMarkdown.test.d.ts +1 -0
- package/esm/typings/src/book-components/icons/ArrowIcon.d.ts +9 -0
- package/esm/typings/src/book-components/icons/ResetIcon.d.ts +6 -0
- package/esm/typings/src/book-components/icons/SendIcon.d.ts +8 -0
- package/esm/typings/src/book-components/icons/TemplateIcon.d.ts +8 -0
- package/esm/typings/src/utils/markdown/escapeMarkdownBlock.d.ts +2 -0
- package/esm/typings/src/utils/markdown/humanizeAiText.d.ts +1 -0
- package/esm/typings/src/utils/markdown/humanizeAiTextEllipsis.d.ts +1 -0
- package/esm/typings/src/utils/markdown/humanizeAiTextEmdashed.d.ts +1 -0
- package/esm/typings/src/utils/markdown/humanizeAiTextQuotes.d.ts +1 -0
- package/esm/typings/src/utils/markdown/humanizeAiTextWhitespace.d.ts +1 -0
- package/esm/typings/src/utils/markdown/prettifyMarkdown.d.ts +8 -0
- package/esm/typings/src/utils/markdown/promptbookifyAiText.d.ts +1 -0
- package/esm/typings/src/utils/normalization/capitalize.d.ts +2 -0
- package/esm/typings/src/utils/normalization/decapitalize.d.ts +3 -1
- package/esm/typings/src/utils/normalization/normalizeTo_SCREAMING_CASE.d.ts +2 -0
- package/esm/typings/src/utils/normalization/normalizeTo_snake_case.d.ts +2 -0
- package/esm/typings/src/utils/normalization/normalizeWhitespaces.d.ts +2 -0
- package/esm/typings/src/utils/normalization/removeDiacritics.d.ts +2 -0
- package/esm/typings/src/utils/parseNumber.d.ts +1 -0
- package/esm/typings/src/utils/removeEmojis.d.ts +2 -0
- package/esm/typings/src/utils/removeQuotes.d.ts +1 -0
- package/esm/typings/src/utils/serialization/deepClone.d.ts +1 -0
- package/esm/typings/src/utils/trimCodeBlock.d.ts +1 -0
- package/esm/typings/src/utils/validators/url/isValidUrl.d.ts +1 -0
- package/esm/typings/src/utils/validators/uuid/isValidUuid.d.ts +2 -0
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +23 -2
- package/umd/index.umd.js.map +1 -1
@@ -0,0 +1,21 @@
|
|
1
|
+
import type { string_html, string_markdown } from '../../../types/typeAliases';
|
2
|
+
/**
|
3
|
+
* Convert markdown content to HTML for display in chat messages
|
4
|
+
*
|
5
|
+
* @param markdown - The markdown content to convert
|
6
|
+
* @returns HTML string ready for rendering
|
7
|
+
*
|
8
|
+
* @public exported from `@promptbook/components`
|
9
|
+
* <- TODO: [🧠] Maybe export from `@promptbook/markdown-utils`
|
10
|
+
*/
|
11
|
+
export declare function renderMarkdown(markdown: string_markdown): string_html;
|
12
|
+
/**
|
13
|
+
* Check if content appears to be markdown (contains markdown syntax)
|
14
|
+
*
|
15
|
+
* @param content - Content to check
|
16
|
+
* @returns true if content appears to contain markdown syntax
|
17
|
+
*
|
18
|
+
* @public exported from `@promptbook/components`
|
19
|
+
* <- TODO: [🧠] Maybe export from `@promptbook/markdown-utils`
|
20
|
+
*/
|
21
|
+
export declare function isMarkdownContent(content: string): boolean;
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -3,6 +3,8 @@ import type { string_markdown_text } from '../../types/typeAliases';
|
|
3
3
|
* Function escapeMarkdownBlock will escape markdown block if needed
|
4
4
|
* It is useful when you want have block in block
|
5
5
|
*
|
6
|
+
* Note: [🔂] This function is idempotent.
|
7
|
+
*
|
6
8
|
* @public exported from `@promptbook/markdown-utils`
|
7
9
|
*/
|
8
10
|
export declare function escapeMarkdownBlock(value: string_markdown_text): string_markdown_text;
|
@@ -2,6 +2,7 @@ import { string_markdown } from '../../types/typeAliases';
|
|
2
2
|
/**
|
3
3
|
* Function `humanizeAiText` will remove traces of AI text generation artifacts
|
4
4
|
*
|
5
|
+
* Note: [🔂] This function is idempotent.
|
5
6
|
* Tip: If you want more control, look for other functions for example `humanizeAiTextEmdashed` exported `@promptbook/markdown-utils`
|
6
7
|
*
|
7
8
|
* @public exported from `@promptbook/markdown-utils`
|
@@ -2,6 +2,7 @@ import { string_markdown } from '../../types/typeAliases';
|
|
2
2
|
/**
|
3
3
|
* Change ellipsis character to three dots `…` -> `...`
|
4
4
|
*
|
5
|
+
* Note: [🔂] This function is idempotent.
|
5
6
|
* Tip: If you want to do the full cleanup, look for `humanizeAiText` exported `@promptbook/markdown-utils`
|
6
7
|
*
|
7
8
|
* @public exported from `@promptbook/markdown-utils`
|
@@ -2,6 +2,7 @@ import { string_markdown } from '../../types/typeAliases';
|
|
2
2
|
/**
|
3
3
|
* Change em-dashes to regular dashes `—` -> `-`
|
4
4
|
*
|
5
|
+
* Note: [🔂] This function is idempotent.
|
5
6
|
* Tip: If you want to do the full cleanup, look for `humanizeAiText` exported `@promptbook/markdown-utils`
|
6
7
|
*
|
7
8
|
* @public exported from `@promptbook/markdown-utils`
|
@@ -2,6 +2,7 @@ import { string_markdown } from '../../types/typeAliases';
|
|
2
2
|
/**
|
3
3
|
* Change smart quotes to regular quotes
|
4
4
|
*
|
5
|
+
* Note: [🔂] This function is idempotent.
|
5
6
|
* Tip: If you want to do the full cleanup, look for `humanizeAiText` exported `@promptbook/markdown-utils`
|
6
7
|
*
|
7
8
|
* @public exported from `@promptbook/markdown-utils`
|
@@ -2,6 +2,7 @@ import { string_markdown } from '../../types/typeAliases';
|
|
2
2
|
/**
|
3
3
|
* Change unprintable hard spaces to regular spaces
|
4
4
|
*
|
5
|
+
* Note: [🔂] This function is idempotent.
|
5
6
|
* Tip: If you want to do the full cleanup, look for `humanizeAiText` exported `@promptbook/markdown-utils`
|
6
7
|
*
|
7
8
|
* @public exported from `@promptbook/markdown-utils`
|
@@ -7,3 +7,11 @@ import type { string_html } from '../../types/typeAliases';
|
|
7
7
|
* @private withing the package because of HUGE size of prettier dependency
|
8
8
|
*/
|
9
9
|
export declare function prettifyMarkdown<TContent extends string_html>(content: TContent): TContent;
|
10
|
+
/**
|
11
|
+
* Async version of prettifyMarkdown using dynamic imports
|
12
|
+
*
|
13
|
+
* @param content raw html code
|
14
|
+
* @returns formatted html code
|
15
|
+
* @private withing the package because of HUGE size of prettier dependency
|
16
|
+
*/
|
17
|
+
export declare function prettifyMarkdownAsync<TContent extends string_html>(content: TContent): Promise<TContent>;
|
@@ -6,6 +6,7 @@ import { string_markdown } from '../../types/typeAliases';
|
|
6
6
|
*/
|
7
7
|
export declare function promptbookifyAiText(text: string_markdown): string_markdown;
|
8
8
|
/**
|
9
|
+
* TODO: !!!!! Make the function idempotent and add "Note: [🔂] This function is idempotent."
|
9
10
|
* TODO: [🅾️]!!! Use this across the project where AI text is involved
|
10
11
|
* TODO: [🧠][✌️] Make some Promptbook-native token system
|
11
12
|
*/
|
@@ -9,6 +9,8 @@ export type string_SCREAMING_CASE = string;
|
|
9
9
|
/**
|
10
10
|
* Normalizes a text string to SCREAMING_CASE (all uppercase with underscores).
|
11
11
|
*
|
12
|
+
* Note: [🔂] This function is idempotent.
|
13
|
+
*
|
12
14
|
* @param text The text string to be converted to SCREAMING_CASE format.
|
13
15
|
* @returns The normalized text in SCREAMING_CASE format.
|
14
16
|
* @example 'HELLO_WORLD'
|
@@ -8,6 +8,8 @@ export type string_snake_case = string;
|
|
8
8
|
/**
|
9
9
|
* Normalizes a text string to snake_case format.
|
10
10
|
*
|
11
|
+
* Note: [🔂] This function is idempotent.
|
12
|
+
*
|
11
13
|
* @param text The text string to be converted to snake_case format.
|
12
14
|
* @returns The normalized text in snake_case format.
|
13
15
|
* @example 'hello_world'
|
@@ -1,6 +1,8 @@
|
|
1
1
|
/**
|
2
2
|
* Removes diacritic marks (accents) from characters in a string.
|
3
3
|
*
|
4
|
+
* Note: [🔂] This function is idempotent.
|
5
|
+
*
|
4
6
|
* @param input The string containing diacritics to be normalized.
|
5
7
|
* @returns The string with diacritics removed or normalized.
|
6
8
|
* @public exported from `@promptbook/utils`
|
@@ -1,6 +1,7 @@
|
|
1
1
|
/**
|
2
2
|
* Removes quotes from a string
|
3
3
|
*
|
4
|
+
* Note: [🔂] This function is idempotent.
|
4
5
|
* Tip: This is very useful for post-processing of the result of the LLM model
|
5
6
|
* Note: This function removes only the same quotes from the beginning and the end of the string
|
6
7
|
* Note: There are two similar functions:
|
@@ -2,6 +2,7 @@ import type { WritableDeep } from 'type-fest';
|
|
2
2
|
/**
|
3
3
|
* Creates a deep clone of the given object
|
4
4
|
*
|
5
|
+
* Note: [🔂] This function is idempotent.
|
5
6
|
* Note: This method only works for objects that are fully serializable to JSON and do not contain functions, Dates, or special types.
|
6
7
|
*
|
7
8
|
* @param objectValue The object to clone.
|
@@ -1,6 +1,7 @@
|
|
1
1
|
/**
|
2
2
|
* Function trimCodeBlock will trim starting and ending code block from the string if it is present.
|
3
3
|
*
|
4
|
+
* Note: [🔂] This function is idempotent.
|
4
5
|
* Note: This is useful for post-processing of the result of the chat LLM model
|
5
6
|
* when the model wraps the result in the (markdown) code block.
|
6
7
|
*
|
@@ -3,6 +3,7 @@ import type { really_unknown } from '../../organization/really_unknown';
|
|
3
3
|
/**
|
4
4
|
* Tests if given string is valid URL.
|
5
5
|
*
|
6
|
+
* Note: [🔂] This function is idempotent.
|
6
7
|
* Note: Dataurl are considered perfectly valid.
|
7
8
|
* Note: There are two similar functions:
|
8
9
|
* - `isValidUrl` which tests any URL
|
@@ -3,6 +3,8 @@ import type { really_unknown } from '../../organization/really_unknown';
|
|
3
3
|
/**
|
4
4
|
* Checks if value is valid uuid
|
5
5
|
*
|
6
|
+
* Note: [🔂] This function is idempotent.
|
7
|
+
*
|
6
8
|
* @public exported from `@promptbook/utils`
|
7
9
|
*/
|
8
10
|
export declare function isValidUuid(value: really_unknown): value is string_uuid;
|
@@ -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.
|
18
|
+
* It follows semantic versioning (e.g., `0.101.0-1`).
|
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.101.0-
|
25
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.101.0-2';
|
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
|
@@ -399,6 +399,7 @@
|
|
399
399
|
/**
|
400
400
|
* Creates a deep clone of the given object
|
401
401
|
*
|
402
|
+
* Note: [🔂] This function is idempotent.
|
402
403
|
* Note: This method only works for objects that are fully serializable to JSON and do not contain functions, Dates, or special types.
|
403
404
|
*
|
404
405
|
* @param objectValue The object to clone.
|
@@ -554,6 +555,8 @@
|
|
554
555
|
/**
|
555
556
|
* Removes emojis from a string and fix whitespaces
|
556
557
|
*
|
558
|
+
* Note: [🔂] This function is idempotent.
|
559
|
+
*
|
557
560
|
* @param text with emojis
|
558
561
|
* @returns text without emojis
|
559
562
|
* @public exported from `@promptbook/utils`
|
@@ -626,6 +629,7 @@
|
|
626
629
|
/**
|
627
630
|
* Tests if given string is valid URL.
|
628
631
|
*
|
632
|
+
* Note: [🔂] This function is idempotent.
|
629
633
|
* Note: Dataurl are considered perfectly valid.
|
630
634
|
* Note: There are two similar functions:
|
631
635
|
* - `isValidUrl` which tests any URL
|
@@ -899,6 +903,8 @@
|
|
899
903
|
/**
|
900
904
|
* Removes diacritic marks (accents) from characters in a string.
|
901
905
|
*
|
906
|
+
* Note: [🔂] This function is idempotent.
|
907
|
+
*
|
902
908
|
* @param input The string containing diacritics to be normalized.
|
903
909
|
* @returns The string with diacritics removed or normalized.
|
904
910
|
* @public exported from `@promptbook/utils`
|
@@ -2049,6 +2055,8 @@
|
|
2049
2055
|
/**
|
2050
2056
|
* Makes first letter of a string uppercase
|
2051
2057
|
*
|
2058
|
+
* Note: [🔂] This function is idempotent.
|
2059
|
+
*
|
2052
2060
|
* @public exported from `@promptbook/utils`
|
2053
2061
|
*/
|
2054
2062
|
function capitalize(word) {
|
@@ -2056,7 +2064,9 @@
|
|
2056
2064
|
}
|
2057
2065
|
|
2058
2066
|
/**
|
2059
|
-
* Makes first letter of a string
|
2067
|
+
* Makes first letter of a string lowercase
|
2068
|
+
*
|
2069
|
+
* Note: [🔂] This function is idempotent.
|
2060
2070
|
*
|
2061
2071
|
* @public exported from `@promptbook/utils`
|
2062
2072
|
*/
|
@@ -2067,6 +2077,8 @@
|
|
2067
2077
|
/**
|
2068
2078
|
* Normalizes a text string to SCREAMING_CASE (all uppercase with underscores).
|
2069
2079
|
*
|
2080
|
+
* Note: [🔂] This function is idempotent.
|
2081
|
+
*
|
2070
2082
|
* @param text The text string to be converted to SCREAMING_CASE format.
|
2071
2083
|
* @returns The normalized text in SCREAMING_CASE format.
|
2072
2084
|
* @example 'HELLO_WORLD'
|
@@ -2199,6 +2211,8 @@
|
|
2199
2211
|
/**
|
2200
2212
|
* Normalizes a text string to snake_case format.
|
2201
2213
|
*
|
2214
|
+
* Note: [🔂] This function is idempotent.
|
2215
|
+
*
|
2202
2216
|
* @param text The text string to be converted to snake_case format.
|
2203
2217
|
* @returns The normalized text in snake_case format.
|
2204
2218
|
* @example 'hello_world'
|
@@ -2212,6 +2226,8 @@
|
|
2212
2226
|
/**
|
2213
2227
|
* Take every whitespace (space, new line, tab) and replace it with a single space
|
2214
2228
|
*
|
2229
|
+
* Note: [🔂] This function is idempotent.
|
2230
|
+
*
|
2215
2231
|
* @public exported from `@promptbook/utils`
|
2216
2232
|
*/
|
2217
2233
|
function normalizeWhitespaces(sentence) {
|
@@ -2313,6 +2329,7 @@
|
|
2313
2329
|
/**
|
2314
2330
|
* Function parseNumber will parse number from string
|
2315
2331
|
*
|
2332
|
+
* Note: [🔂] This function is idempotent.
|
2316
2333
|
* Unlike Number.parseInt, Number.parseFloat it will never ever result in NaN
|
2317
2334
|
* Note: it also works only with decimal numbers
|
2318
2335
|
*
|
@@ -2381,6 +2398,7 @@
|
|
2381
2398
|
/**
|
2382
2399
|
* Removes quotes from a string
|
2383
2400
|
*
|
2401
|
+
* Note: [🔂] This function is idempotent.
|
2384
2402
|
* Tip: This is very useful for post-processing of the result of the LLM model
|
2385
2403
|
* Note: This function removes only the same quotes from the beginning and the end of the string
|
2386
2404
|
* Note: There are two similar functions:
|
@@ -2560,6 +2578,7 @@
|
|
2560
2578
|
/**
|
2561
2579
|
* Function trimCodeBlock will trim starting and ending code block from the string if it is present.
|
2562
2580
|
*
|
2581
|
+
* Note: [🔂] This function is idempotent.
|
2563
2582
|
* Note: This is useful for post-processing of the result of the chat LLM model
|
2564
2583
|
* when the model wraps the result in the (markdown) code block.
|
2565
2584
|
*
|
@@ -2838,6 +2857,8 @@
|
|
2838
2857
|
/**
|
2839
2858
|
* Checks if value is valid uuid
|
2840
2859
|
*
|
2860
|
+
* Note: [🔂] This function is idempotent.
|
2861
|
+
*
|
2841
2862
|
* @public exported from `@promptbook/utils`
|
2842
2863
|
*/
|
2843
2864
|
function isValidUuid(value) {
|