@promptbook/markdown-utils 0.100.4-0 → 0.101.0-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/esm/index.es.js +158 -7
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/src/_packages/components.index.d.ts +4 -0
  4. package/esm/typings/src/_packages/core.index.d.ts +4 -2
  5. package/esm/typings/src/_packages/markdown-utils.index.d.ts +14 -0
  6. package/esm/typings/src/_packages/types.index.d.ts +4 -6
  7. package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +21 -0
  8. package/esm/typings/src/book-2.0/{commitments/_misc → agent-source}/AgentModelRequirements.d.ts +1 -1
  9. package/esm/typings/src/book-2.0/{commitments/_misc → agent-source}/AgentSourceParseResult.d.ts +3 -1
  10. package/esm/typings/src/book-2.0/{commitments/_misc → agent-source}/createAgentModelRequirements.d.ts +2 -2
  11. package/esm/typings/src/book-2.0/{commitments/_misc → agent-source}/createAgentModelRequirementsWithCommitments.d.ts +3 -3
  12. package/esm/typings/src/book-2.0/{commitments/_misc → agent-source}/createCommitmentRegex.d.ts +2 -2
  13. package/esm/typings/src/book-2.0/agent-source/extractMetaLinks.d.ts +8 -0
  14. package/esm/typings/src/book-2.0/agent-source/parseAgentSource.d.ts +4 -19
  15. package/esm/typings/src/book-2.0/agent-source/parseAgentSourceWithCommitments.d.ts +9 -0
  16. package/esm/typings/src/book-2.0/commitments/ACTION/ACTION.d.ts +1 -1
  17. package/esm/typings/src/book-2.0/commitments/FORMAT/FORMAT.d.ts +1 -1
  18. package/esm/typings/src/book-2.0/commitments/KNOWLEDGE/KNOWLEDGE.d.ts +1 -1
  19. package/esm/typings/src/book-2.0/commitments/META_IMAGE/META_IMAGE.d.ts +1 -1
  20. package/esm/typings/src/book-2.0/commitments/META_LINK/META_LINK.d.ts +1 -1
  21. package/esm/typings/src/book-2.0/commitments/MODEL/MODEL.d.ts +1 -1
  22. package/esm/typings/src/book-2.0/commitments/NOTE/NOTE.d.ts +1 -1
  23. package/esm/typings/src/book-2.0/commitments/PERSONA/PERSONA.d.ts +1 -1
  24. package/esm/typings/src/book-2.0/commitments/RULE/RULE.d.ts +1 -1
  25. package/esm/typings/src/book-2.0/commitments/SAMPLE/SAMPLE.d.ts +1 -1
  26. package/esm/typings/src/book-2.0/commitments/STYLE/STYLE.d.ts +1 -1
  27. package/esm/typings/src/book-2.0/commitments/_base/BaseCommitmentDefinition.d.ts +1 -1
  28. package/esm/typings/src/book-2.0/commitments/_base/CommitmentDefinition.d.ts +1 -1
  29. package/esm/typings/src/book-2.0/commitments/_base/NotYetImplementedCommitmentDefinition.d.ts +1 -1
  30. package/esm/typings/src/book-2.0/commitments/{_misc → _base}/ParsedCommitment.d.ts +1 -1
  31. package/esm/typings/src/book-2.0/commitments/_base/createEmptyAgentModelRequirements.d.ts +1 -1
  32. package/esm/typings/src/book-2.0/utils/extractAgentMetadata.d.ts +17 -0
  33. package/esm/typings/src/book-2.0/utils/extractProfileImageFromSystemMessage.d.ts +12 -0
  34. package/esm/typings/src/book-2.0/utils/generateGravatarUrl.d.ts +10 -0
  35. package/esm/typings/src/book-2.0/utils/generatePlaceholderAgentProfileImageUrl.d.ts +10 -0
  36. package/esm/typings/src/book-components/AvatarProfile/AvatarChip/AvatarChip.d.ts +1 -1
  37. package/esm/typings/src/book-components/AvatarProfile/AvatarProfile/AvatarProfile.d.ts +2 -8
  38. package/esm/typings/src/book-components/Chat/Chat/ChatProps.d.ts +6 -0
  39. package/esm/typings/src/book-components/Chat/examples/ChatMarkdownDemo.d.ts +16 -0
  40. package/esm/typings/src/book-components/Chat/types/ChatParticipant.d.ts +1 -1
  41. package/esm/typings/src/book-components/Chat/utils/renderMarkdown.d.ts +21 -0
  42. package/esm/typings/src/book-components/Chat/utils/renderMarkdown.test.d.ts +1 -0
  43. package/esm/typings/src/llm-providers/_common/profiles/llmProviderProfiles.d.ts +1 -1
  44. package/esm/typings/src/utils/expectation-counters/countCharacters.d.ts +2 -1
  45. package/esm/typings/src/utils/expectation-counters/countLines.d.ts +2 -1
  46. package/esm/typings/src/utils/expectation-counters/countPages.d.ts +2 -1
  47. package/esm/typings/src/utils/expectation-counters/countParagraphs.d.ts +2 -1
  48. package/esm/typings/src/utils/expectation-counters/countSentences.d.ts +1 -0
  49. package/esm/typings/src/utils/expectation-counters/countWords.d.ts +3 -1
  50. package/esm/typings/src/utils/markdown/escapeMarkdownBlock.d.ts +2 -0
  51. package/esm/typings/src/utils/markdown/humanizeAiText.d.ts +13 -0
  52. package/esm/typings/src/utils/markdown/humanizeAiText.test.d.ts +1 -0
  53. package/esm/typings/src/utils/markdown/humanizeAiTextEllipsis.d.ts +13 -0
  54. package/esm/typings/src/utils/markdown/humanizeAiTextEmdashed.d.ts +13 -0
  55. package/esm/typings/src/utils/markdown/humanizeAiTextQuotes.d.ts +13 -0
  56. package/esm/typings/src/utils/markdown/humanizeAiTextWhitespace.d.ts +13 -0
  57. package/esm/typings/src/utils/markdown/prettifyMarkdown.d.ts +8 -0
  58. package/esm/typings/src/utils/markdown/promptbookifyAiText.d.ts +12 -0
  59. package/esm/typings/src/utils/markdown/promptbookifyAiText.test.d.ts +1 -0
  60. package/esm/typings/src/utils/markdown/removeMarkdownLinks.d.ts +11 -0
  61. package/esm/typings/src/utils/markdown/removeMarkdownLinks.test.d.ts +4 -0
  62. package/esm/typings/src/utils/normalization/capitalize.d.ts +2 -0
  63. package/esm/typings/src/utils/normalization/decapitalize.d.ts +3 -1
  64. package/esm/typings/src/utils/normalization/normalizeTo_SCREAMING_CASE.d.ts +2 -0
  65. package/esm/typings/src/utils/normalization/normalizeTo_snake_case.d.ts +2 -0
  66. package/esm/typings/src/utils/normalization/normalizeWhitespaces.d.ts +2 -0
  67. package/esm/typings/src/utils/normalization/removeDiacritics.d.ts +2 -0
  68. package/esm/typings/src/utils/parseNumber.d.ts +1 -0
  69. package/esm/typings/src/utils/removeEmojis.d.ts +2 -0
  70. package/esm/typings/src/utils/removeQuotes.d.ts +1 -0
  71. package/esm/typings/src/utils/serialization/deepClone.d.ts +1 -0
  72. package/esm/typings/src/utils/trimCodeBlock.d.ts +1 -0
  73. package/esm/typings/src/utils/validators/url/isValidUrl.d.ts +1 -0
  74. package/esm/typings/src/utils/validators/uuid/isValidUuid.d.ts +2 -0
  75. package/esm/typings/src/version.d.ts +1 -1
  76. package/package.json +1 -1
  77. package/umd/index.umd.js +169 -10
  78. package/umd/index.umd.js.map +1 -1
  79. package/esm/typings/src/book-2.0/commitments/_misc/parseAgentSourceWithCommitments.d.ts +0 -24
  80. package/esm/typings/src/book-2.0/utils/profileImageUtils.d.ts +0 -39
  81. /package/esm/typings/src/book-2.0/{commitments/_misc → agent-source}/removeCommentsFromSystemMessage.d.ts +0 -0
package/esm/index.es.js CHANGED
@@ -1,7 +1,4 @@
1
1
  import spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
2
- import parserHtml from 'prettier/parser-html';
3
- import parserMarkdown from 'prettier/parser-markdown';
4
- import { format } from 'prettier/standalone';
5
2
  import { randomBytes } from 'crypto';
6
3
  import { Subject } from 'rxjs';
7
4
  import { forTime } from 'waitasecond';
@@ -26,7 +23,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
26
23
  * @generated
27
24
  * @see https://github.com/webgptorg/promptbook
28
25
  */
29
- const PROMPTBOOK_ENGINE_VERSION = '0.100.4-0';
26
+ const PROMPTBOOK_ENGINE_VERSION = '0.101.0-1';
30
27
  /**
31
28
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
32
29
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -51,6 +48,8 @@ class ParseError extends Error {
51
48
  /**
52
49
  * Makes first letter of a string uppercase
53
50
  *
51
+ * Note: [🔂] This function is idempotent.
52
+ *
54
53
  * @public exported from `@promptbook/utils`
55
54
  */
56
55
  function capitalize(word) {
@@ -642,6 +641,7 @@ function isValidFilePath(filename) {
642
641
  /**
643
642
  * Tests if given string is valid URL.
644
643
  *
644
+ * Note: [🔂] This function is idempotent.
645
645
  * Note: Dataurl are considered perfectly valid.
646
646
  * Note: There are two similar functions:
647
647
  * - `isValidUrl` which tests any URL
@@ -705,8 +705,18 @@ function validatePipelineString(pipelineString) {
705
705
  * @private withing the package because of HUGE size of prettier dependency
706
706
  */
707
707
  function prettifyMarkdown(content) {
708
+ // In browser/Next.js environments, just return the original content
709
+ // since prettier parsers are not available and would cause bundling issues
710
+ if (typeof window !== 'undefined') {
711
+ return content;
712
+ }
708
713
  try {
709
- return format(content, {
714
+ // Use dynamic require to avoid static imports that cause bundling issues
715
+ // This will only work in Node.js environments
716
+ const prettierStandalone = eval('require')('prettier/standalone');
717
+ const parserMarkdown = eval('require')('prettier/parser-markdown');
718
+ const parserHtml = eval('require')('prettier/parser-html');
719
+ return prettierStandalone.format(content, {
710
720
  parser: 'markdown',
711
721
  plugins: [parserMarkdown, parserHtml],
712
722
  // TODO: DRY - make some import or auto-copy of .prettierrc
@@ -1054,6 +1064,7 @@ function checkSerializableAsJson(options) {
1054
1064
  /**
1055
1065
  * Creates a deep clone of the given object
1056
1066
  *
1067
+ * Note: [🔂] This function is idempotent.
1057
1068
  * Note: This method only works for objects that are fully serializable to JSON and do not contain functions, Dates, or special types.
1058
1069
  *
1059
1070
  * @param objectValue The object to clone.
@@ -2680,7 +2691,7 @@ const LLM_PROVIDER_PROFILES = {
2680
2691
  };
2681
2692
  /**
2682
2693
  * TODO: Refactor this - each profile must be alongside the provider definition
2683
- * TODO: [🕛] Unite `AvatarProfileProps`, `ChatParticipant`, `LlmExecutionTools` + `LlmToolsMetadata`
2694
+ * TODO: [🕛] Unite `AgentBasicInformation`, `ChatParticipant`, `LlmExecutionTools` + `LlmToolsMetadata`
2684
2695
  * Note: [💞] Ignore a discrepancy between file name and entity name
2685
2696
  */
2686
2697
 
@@ -2989,6 +3000,8 @@ function $getGlobalScope() {
2989
3000
  /**
2990
3001
  * Normalizes a text string to SCREAMING_CASE (all uppercase with underscores).
2991
3002
  *
3003
+ * Note: [🔂] This function is idempotent.
3004
+ *
2992
3005
  * @param text The text string to be converted to SCREAMING_CASE format.
2993
3006
  * @returns The normalized text in SCREAMING_CASE format.
2994
3007
  * @example 'HELLO_WORLD'
@@ -3044,6 +3057,8 @@ function normalizeTo_SCREAMING_CASE(text) {
3044
3057
  /**
3045
3058
  * Normalizes a text string to snake_case format.
3046
3059
  *
3060
+ * Note: [🔂] This function is idempotent.
3061
+ *
3047
3062
  * @param text The text string to be converted to snake_case format.
3048
3063
  * @returns The normalized text in snake_case format.
3049
3064
  * @example 'hello_world'
@@ -3461,6 +3476,8 @@ for (let i = 0; i < defaultDiacriticsRemovalMap.length; i++) {
3461
3476
  /**
3462
3477
  * Removes diacritic marks (accents) from characters in a string.
3463
3478
  *
3479
+ * Note: [🔂] This function is idempotent.
3480
+ *
3464
3481
  * @param input The string containing diacritics to be normalized.
3465
3482
  * @returns The string with diacritics removed or normalized.
3466
3483
  * @public exported from `@promptbook/utils`
@@ -3615,6 +3632,8 @@ function mimeTypeToExtension(value) {
3615
3632
  /**
3616
3633
  * Removes emojis from a string and fix whitespaces
3617
3634
  *
3635
+ * Note: [🔂] This function is idempotent.
3636
+ *
3618
3637
  * @param text with emojis
3619
3638
  * @returns text without emojis
3620
3639
  * @public exported from `@promptbook/utils`
@@ -4889,6 +4908,7 @@ function countCharacters(text) {
4889
4908
  }
4890
4909
  /**
4891
4910
  * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4911
+ * TODO: [🧠][✌️] Make some Promptbook-native token system
4892
4912
  */
4893
4913
 
4894
4914
  /**
@@ -4923,6 +4943,7 @@ function countLines(text) {
4923
4943
  }
4924
4944
  /**
4925
4945
  * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4946
+ * TODO: [🧠][✌️] Make some Promptbook-native token system
4926
4947
  */
4927
4948
 
4928
4949
  /**
@@ -4937,6 +4958,7 @@ function countPages(text) {
4937
4958
  }
4938
4959
  /**
4939
4960
  * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4961
+ * TODO: [🧠][✌️] Make some Promptbook-native token system
4940
4962
  */
4941
4963
 
4942
4964
  /**
@@ -4949,6 +4971,7 @@ function countParagraphs(text) {
4949
4971
  }
4950
4972
  /**
4951
4973
  * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4974
+ * TODO: [🧠][✌️] Make some Promptbook-native token system
4952
4975
  */
4953
4976
 
4954
4977
  /**
@@ -4969,6 +4992,7 @@ function countSentences(text) {
4969
4992
  }
4970
4993
  /**
4971
4994
  * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4995
+ * TODO: [🧠][✌️] Make some Promptbook-native token system
4972
4996
  */
4973
4997
 
4974
4998
  /**
@@ -4985,6 +5009,8 @@ function countWords(text) {
4985
5009
  }
4986
5010
  /**
4987
5011
  * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
5012
+ * TODO: [🧠][✌️] Make some Promptbook-native token system
5013
+ * TODO: [✌️] `countWords` should be just `splitWords(...).length`, and all other counters should use this pattern as well
4988
5014
  */
4989
5015
 
4990
5016
  /**
@@ -6609,6 +6635,8 @@ function createMarkdownChart(options) {
6609
6635
  * Function escapeMarkdownBlock will escape markdown block if needed
6610
6636
  * It is useful when you want have block in block
6611
6637
  *
6638
+ * Note: [🔂] This function is idempotent.
6639
+ *
6612
6640
  * @public exported from `@promptbook/markdown-utils`
6613
6641
  */
6614
6642
  function escapeMarkdownBlock(value) {
@@ -6773,6 +6801,114 @@ function flattenMarkdown(markdown) {
6773
6801
  * NOW we are working just with markdown string and its good enough
6774
6802
  */
6775
6803
 
6804
+ /**
6805
+ * Change ellipsis character to three dots `…` -> `...`
6806
+ *
6807
+ * Note: [🔂] This function is idempotent.
6808
+ * Tip: If you want to do the full cleanup, look for `humanizeAiText` exported `@promptbook/markdown-utils`
6809
+ *
6810
+ * @public exported from `@promptbook/markdown-utils`
6811
+ */
6812
+ function humanizeAiTextEllipsis(aiText) {
6813
+ return aiText.replace(/…/g, '...');
6814
+ }
6815
+ /**
6816
+ * Note: [🏂] This function is not tested by itself but together with other cleanup functions with `humanizeAiText`
6817
+ */
6818
+
6819
+ /**
6820
+ * Change em-dashes to regular dashes `—` -> `-`
6821
+ *
6822
+ * Note: [🔂] This function is idempotent.
6823
+ * Tip: If you want to do the full cleanup, look for `humanizeAiText` exported `@promptbook/markdown-utils`
6824
+ *
6825
+ * @public exported from `@promptbook/markdown-utils`
6826
+ */
6827
+ function humanizeAiTextEmdashed(aiText) {
6828
+ return aiText.replace(/—/g, '-');
6829
+ }
6830
+ /**
6831
+ * Note: [🏂] This function is not tested by itself but together with other cleanup functions with `humanizeAiText`
6832
+ */
6833
+
6834
+ /**
6835
+ * Change smart quotes to regular quotes
6836
+ *
6837
+ * Note: [🔂] This function is idempotent.
6838
+ * Tip: If you want to do the full cleanup, look for `humanizeAiText` exported `@promptbook/markdown-utils`
6839
+ *
6840
+ * @public exported from `@promptbook/markdown-utils`
6841
+ */
6842
+ function humanizeAiTextQuotes(aiText) {
6843
+ return aiText
6844
+ .replace(/[“”]/g, '"')
6845
+ .replace(/[‚‘’]/g, "'")
6846
+ .replace(/«/g, '"')
6847
+ .replace(/»/g, '"')
6848
+ .replace(/„/g, '"')
6849
+ .replace(/‹/g, "'")
6850
+ .replace(/›/g, "'");
6851
+ }
6852
+ /**
6853
+ * Note: [🏂] This function is not tested by itself but together with other cleanup functions with `humanizeAiText`
6854
+ */
6855
+
6856
+ /**
6857
+ * Change unprintable hard spaces to regular spaces
6858
+ *
6859
+ * Note: [🔂] This function is idempotent.
6860
+ * Tip: If you want to do the full cleanup, look for `humanizeAiText` exported `@promptbook/markdown-utils`
6861
+ *
6862
+ * @public exported from `@promptbook/markdown-utils`
6863
+ */
6864
+ function humanizeAiTextWhitespace(aiText) {
6865
+ return aiText.replace(/\u00A0/g, ' ');
6866
+ }
6867
+ /**
6868
+ * Note: [🏂] This function is not tested by itself but together with other cleanup functions with `humanizeAiText`
6869
+ */
6870
+
6871
+ /**
6872
+ * Function `humanizeAiText` will remove traces of AI text generation artifacts
6873
+ *
6874
+ * Note: [🔂] This function is idempotent.
6875
+ * Tip: If you want more control, look for other functions for example `humanizeAiTextEmdashed` exported `@promptbook/markdown-utils`
6876
+ *
6877
+ * @public exported from `@promptbook/markdown-utils`
6878
+ */
6879
+ function humanizeAiText(aiText) {
6880
+ let cleanedText = aiText;
6881
+ cleanedText = humanizeAiTextEllipsis(cleanedText);
6882
+ cleanedText = humanizeAiTextEmdashed(cleanedText);
6883
+ cleanedText = humanizeAiTextQuotes(cleanedText);
6884
+ cleanedText = humanizeAiTextWhitespace(cleanedText);
6885
+ return cleanedText;
6886
+ }
6887
+ /**
6888
+ * TODO: [🅾️] !!! Use this across the project where AI text is involved
6889
+ */
6890
+
6891
+ /**
6892
+ * Function `promptbookifyAiText` will slightly modify the text so we know it was processed by Promptbook
6893
+ *
6894
+ * @public exported from `@promptbook/markdown-utils`
6895
+ */
6896
+ function promptbookifyAiText(text) {
6897
+ // Note: Duplicating some spaces
6898
+ const words = text.split(' '); // <- Note: [✌️] Use `splitWords` when available
6899
+ const wordLength = words.length; // <- Note: [✌️] `countWords` should be just `splitWords(...).length`
6900
+ for (const wordIndex of [3, 7, 11, 19].filter((i) => i < wordLength)) {
6901
+ words[wordIndex] = ' ' + words[wordIndex];
6902
+ }
6903
+ const promptbookifiedText = words.join(' ');
6904
+ return promptbookifiedText;
6905
+ }
6906
+ /**
6907
+ * TODO: !!!!! Make the function idempotent and add "Note: [🔂] This function is idempotent."
6908
+ * TODO: [🅾️]!!! Use this across the project where AI text is involved
6909
+ * TODO: [🧠][✌️] Make some Promptbook-native token system
6910
+ */
6911
+
6776
6912
  /**
6777
6913
  * Removes Markdown formatting tags from a string.
6778
6914
  *
@@ -6790,5 +6926,20 @@ function removeMarkdownFormatting(str) {
6790
6926
  return str;
6791
6927
  }
6792
6928
 
6793
- export { BOOK_LANGUAGE_VERSION, MarkdownScraper, PROMPTBOOK_ENGINE_VERSION, _MarkdownScraperRegistration, addAutoGeneratedSection, createMarkdownChart, createMarkdownScraper, createMarkdownTable, escapeMarkdownBlock, extractAllBlocksFromMarkdown, extractAllListItemsFromMarkdown, extractBlock, extractJsonBlock, extractOneBlockFromMarkdown, flattenMarkdown, parseMarkdownSection, removeMarkdownComments, removeMarkdownFormatting, splitMarkdownIntoSections };
6929
+ /**
6930
+ * Removes Markdown link tags from a string.
6931
+ *
6932
+ * @param {string} str - The string to remove Markdown tags from.
6933
+ * @returns {string} The input string with all Markdown tags removed.
6934
+ * @public exported from `@promptbook/markdown-utils`
6935
+ */
6936
+ function removeMarkdownLinks(str) {
6937
+ // Use regular expressions to remove Markdown tags from the string
6938
+ return str.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '$1');
6939
+ }
6940
+ /**
6941
+ * @see https://chat.openai.com/chat/bb7c3a5b-fe9c-4ccc-9057-f47e0fd66489
6942
+ */
6943
+
6944
+ export { BOOK_LANGUAGE_VERSION, MarkdownScraper, PROMPTBOOK_ENGINE_VERSION, _MarkdownScraperRegistration, addAutoGeneratedSection, createMarkdownChart, createMarkdownScraper, createMarkdownTable, escapeMarkdownBlock, extractAllBlocksFromMarkdown, extractAllListItemsFromMarkdown, extractBlock, extractJsonBlock, extractOneBlockFromMarkdown, flattenMarkdown, humanizeAiText, humanizeAiTextEllipsis, humanizeAiTextEmdashed, humanizeAiTextQuotes, humanizeAiTextWhitespace, parseMarkdownSection, promptbookifyAiText, removeMarkdownComments, removeMarkdownFormatting, removeMarkdownLinks, splitMarkdownIntoSections };
6794
6945
  //# sourceMappingURL=index.es.js.map