@promptbook/cli 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 (82) hide show
  1. package/README.md +68 -1
  2. package/esm/index.es.js +42 -7
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/components.index.d.ts +4 -0
  5. package/esm/typings/src/_packages/core.index.d.ts +4 -2
  6. package/esm/typings/src/_packages/markdown-utils.index.d.ts +14 -0
  7. package/esm/typings/src/_packages/types.index.d.ts +4 -6
  8. package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +21 -0
  9. package/esm/typings/src/book-2.0/{commitments/_misc → agent-source}/AgentModelRequirements.d.ts +1 -1
  10. package/esm/typings/src/book-2.0/{commitments/_misc → agent-source}/AgentSourceParseResult.d.ts +3 -1
  11. package/esm/typings/src/book-2.0/{commitments/_misc → agent-source}/createAgentModelRequirements.d.ts +2 -2
  12. package/esm/typings/src/book-2.0/{commitments/_misc → agent-source}/createAgentModelRequirementsWithCommitments.d.ts +3 -3
  13. package/esm/typings/src/book-2.0/{commitments/_misc → agent-source}/createCommitmentRegex.d.ts +2 -2
  14. package/esm/typings/src/book-2.0/agent-source/extractMetaLinks.d.ts +8 -0
  15. package/esm/typings/src/book-2.0/agent-source/parseAgentSource.d.ts +4 -19
  16. package/esm/typings/src/book-2.0/agent-source/parseAgentSourceWithCommitments.d.ts +9 -0
  17. package/esm/typings/src/book-2.0/commitments/ACTION/ACTION.d.ts +1 -1
  18. package/esm/typings/src/book-2.0/commitments/FORMAT/FORMAT.d.ts +1 -1
  19. package/esm/typings/src/book-2.0/commitments/KNOWLEDGE/KNOWLEDGE.d.ts +1 -1
  20. package/esm/typings/src/book-2.0/commitments/META_IMAGE/META_IMAGE.d.ts +1 -1
  21. package/esm/typings/src/book-2.0/commitments/META_LINK/META_LINK.d.ts +1 -1
  22. package/esm/typings/src/book-2.0/commitments/MODEL/MODEL.d.ts +1 -1
  23. package/esm/typings/src/book-2.0/commitments/NOTE/NOTE.d.ts +1 -1
  24. package/esm/typings/src/book-2.0/commitments/PERSONA/PERSONA.d.ts +1 -1
  25. package/esm/typings/src/book-2.0/commitments/RULE/RULE.d.ts +1 -1
  26. package/esm/typings/src/book-2.0/commitments/SAMPLE/SAMPLE.d.ts +1 -1
  27. package/esm/typings/src/book-2.0/commitments/STYLE/STYLE.d.ts +1 -1
  28. package/esm/typings/src/book-2.0/commitments/_base/BaseCommitmentDefinition.d.ts +1 -1
  29. package/esm/typings/src/book-2.0/commitments/_base/CommitmentDefinition.d.ts +1 -1
  30. package/esm/typings/src/book-2.0/commitments/_base/NotYetImplementedCommitmentDefinition.d.ts +1 -1
  31. package/esm/typings/src/book-2.0/commitments/{_misc → _base}/ParsedCommitment.d.ts +1 -1
  32. package/esm/typings/src/book-2.0/commitments/_base/createEmptyAgentModelRequirements.d.ts +1 -1
  33. package/esm/typings/src/book-2.0/utils/extractAgentMetadata.d.ts +17 -0
  34. package/esm/typings/src/book-2.0/utils/extractProfileImageFromSystemMessage.d.ts +12 -0
  35. package/esm/typings/src/book-2.0/utils/generateGravatarUrl.d.ts +10 -0
  36. package/esm/typings/src/book-2.0/utils/generatePlaceholderAgentProfileImageUrl.d.ts +10 -0
  37. package/esm/typings/src/book-components/AvatarProfile/AvatarChip/AvatarChip.d.ts +1 -1
  38. package/esm/typings/src/book-components/AvatarProfile/AvatarProfile/AvatarProfile.d.ts +2 -8
  39. package/esm/typings/src/book-components/Chat/Chat/ChatProps.d.ts +6 -0
  40. package/esm/typings/src/book-components/Chat/examples/ChatMarkdownDemo.d.ts +16 -0
  41. package/esm/typings/src/book-components/Chat/types/ChatParticipant.d.ts +1 -1
  42. package/esm/typings/src/book-components/Chat/utils/renderMarkdown.d.ts +21 -0
  43. package/esm/typings/src/book-components/Chat/utils/renderMarkdown.test.d.ts +1 -0
  44. package/esm/typings/src/llm-providers/_common/profiles/llmProviderProfiles.d.ts +1 -1
  45. package/esm/typings/src/utils/expectation-counters/countCharacters.d.ts +2 -1
  46. package/esm/typings/src/utils/expectation-counters/countLines.d.ts +2 -1
  47. package/esm/typings/src/utils/expectation-counters/countPages.d.ts +2 -1
  48. package/esm/typings/src/utils/expectation-counters/countParagraphs.d.ts +2 -1
  49. package/esm/typings/src/utils/expectation-counters/countSentences.d.ts +1 -0
  50. package/esm/typings/src/utils/expectation-counters/countWords.d.ts +3 -1
  51. package/esm/typings/src/utils/markdown/escapeMarkdownBlock.d.ts +2 -0
  52. package/esm/typings/src/utils/markdown/humanizeAiText.d.ts +13 -0
  53. package/esm/typings/src/utils/markdown/humanizeAiText.test.d.ts +1 -0
  54. package/esm/typings/src/utils/markdown/humanizeAiTextEllipsis.d.ts +13 -0
  55. package/esm/typings/src/utils/markdown/humanizeAiTextEmdashed.d.ts +13 -0
  56. package/esm/typings/src/utils/markdown/humanizeAiTextQuotes.d.ts +13 -0
  57. package/esm/typings/src/utils/markdown/humanizeAiTextWhitespace.d.ts +13 -0
  58. package/esm/typings/src/utils/markdown/prettifyMarkdown.d.ts +8 -0
  59. package/esm/typings/src/utils/markdown/promptbookifyAiText.d.ts +12 -0
  60. package/esm/typings/src/utils/markdown/promptbookifyAiText.test.d.ts +1 -0
  61. package/esm/typings/src/utils/markdown/removeMarkdownLinks.d.ts +11 -0
  62. package/esm/typings/src/utils/markdown/removeMarkdownLinks.test.d.ts +4 -0
  63. package/esm/typings/src/utils/normalization/capitalize.d.ts +2 -0
  64. package/esm/typings/src/utils/normalization/decapitalize.d.ts +3 -1
  65. package/esm/typings/src/utils/normalization/normalizeTo_SCREAMING_CASE.d.ts +2 -0
  66. package/esm/typings/src/utils/normalization/normalizeTo_snake_case.d.ts +2 -0
  67. package/esm/typings/src/utils/normalization/normalizeWhitespaces.d.ts +2 -0
  68. package/esm/typings/src/utils/normalization/removeDiacritics.d.ts +2 -0
  69. package/esm/typings/src/utils/parseNumber.d.ts +1 -0
  70. package/esm/typings/src/utils/removeEmojis.d.ts +2 -0
  71. package/esm/typings/src/utils/removeQuotes.d.ts +1 -0
  72. package/esm/typings/src/utils/serialization/deepClone.d.ts +1 -0
  73. package/esm/typings/src/utils/trimCodeBlock.d.ts +1 -0
  74. package/esm/typings/src/utils/validators/url/isValidUrl.d.ts +1 -0
  75. package/esm/typings/src/utils/validators/uuid/isValidUuid.d.ts +2 -0
  76. package/esm/typings/src/version.d.ts +1 -1
  77. package/package.json +1 -1
  78. package/umd/index.umd.js +47 -11
  79. package/umd/index.umd.js.map +1 -1
  80. package/esm/typings/src/book-2.0/commitments/_misc/parseAgentSourceWithCommitments.d.ts +0 -24
  81. package/esm/typings/src/book-2.0/utils/profileImageUtils.d.ts +0 -39
  82. /package/esm/typings/src/book-2.0/{commitments/_misc → agent-source}/removeCommentsFromSystemMessage.d.ts +0 -0
package/README.md CHANGED
@@ -51,7 +51,31 @@ npm install --save-dev @promptbook/cli
51
51
  npm install --global @promptbook/cli
52
52
  ```
53
53
 
54
- CLI utils for Promptbook. After install you can use `promptbook` command in terminal:
54
+ CLI utilities for Promptbook that provide command-line tools for building, prettifying, and managing promptbook collections. After installation, you can use the `ptbk` command in your terminal.
55
+
56
+ ## 🎯 Purpose and Motivation
57
+
58
+ The CLI package provides essential command-line tools for Promptbook development workflows. It enables developers to build optimized promptbook libraries, prettify promptbook files, and manage collections efficiently from the command line, making it easier to integrate Promptbook into development and deployment pipelines.
59
+
60
+ ## 🔧 High-Level Functionality
61
+
62
+ The package provides command-line tools for:
63
+ - **Library Building**: Pre-compile promptbook collections into optimized formats
64
+ - **Code Generation**: Generate TypeScript, JavaScript, or JSON libraries
65
+ - **Prettification**: Format and enhance promptbook files with diagrams
66
+ - **Validation**: Check promptbooks for errors during build time
67
+ - **Knowledge Building**: Build RAG (Retrieval-Augmented Generation) knowledge bases
68
+ - **Provider Registration**: Include all LLM providers and scrapers for CLI operations
69
+
70
+ ## ✨ Key Features
71
+
72
+ - 🏗️ **Pre-compilation** - Build optimized promptbook libraries at build time
73
+ - 📝 **Code Generation** - Generate TypeScript, JavaScript, or JSON outputs
74
+ - 🎨 **Auto-prettification** - Format promptbooks and add Mermaid diagrams
75
+ - ✅ **Build-time Validation** - Catch errors early in the development process
76
+ - 🧠 **Knowledge Building** - Automatically build RAG knowledge bases
77
+ - 🔧 **All Providers Included** - Complete set of LLM providers and scrapers
78
+ - 🚀 **Performance Optimization** - Pre-built libraries for faster runtime execution
55
79
 
56
80
  ## Make your Promptbook Library
57
81
 
@@ -104,6 +128,49 @@ npx ptbk prettify 'promptbook/**/*.book'
104
128
 
105
129
  This will prettify all promptbooks in `promptbook` directory and adds Mermaid graphs to them.
106
130
 
131
+ ## 📦 Exported Entities
132
+
133
+ ### Version Information
134
+ - `BOOK_LANGUAGE_VERSION` - Current book language version
135
+ - `PROMPTBOOK_ENGINE_VERSION` - Current engine version
136
+
137
+ ### CLI Core
138
+ - `_CLI` - Main CLI application implementation
139
+
140
+ ### LLM Provider Registrations
141
+ - `_AnthropicClaudeMetadataRegistration` - Anthropic Claude metadata registration
142
+ - `_AnthropicClaudeRegistration` - Anthropic Claude provider registration
143
+ - `_AzureOpenAiMetadataRegistration` - Azure OpenAI metadata registration
144
+ - `_AzureOpenAiRegistration` - Azure OpenAI provider registration
145
+ - `_DeepseekMetadataRegistration` - Deepseek metadata registration
146
+ - `_DeepseekRegistration` - Deepseek provider registration
147
+ - `_GoogleMetadataRegistration` - Google metadata registration
148
+ - `_GoogleRegistration` - Google provider registration
149
+ - `_OllamaMetadataRegistration` - Ollama metadata registration
150
+ - `_OllamaRegistration` - Ollama provider registration
151
+ - `_OpenAiMetadataRegistration` - OpenAI metadata registration
152
+ - `_OpenAiAssistantMetadataRegistration` - OpenAI Assistant metadata registration
153
+ - `_OpenAiCompatibleMetadataRegistration` - OpenAI Compatible metadata registration
154
+ - `_OpenAiRegistration` - OpenAI provider registration
155
+ - `_OpenAiAssistantRegistration` - OpenAI Assistant provider registration
156
+ - `_OpenAiCompatibleRegistration` - OpenAI Compatible provider registration
157
+
158
+ ### Scraper Registrations
159
+ - `_BoilerplateScraperRegistration` - Boilerplate scraper registration
160
+ - `_BoilerplateScraperMetadataRegistration` - Boilerplate scraper metadata registration
161
+ - `_LegacyDocumentScraperRegistration` - Legacy document scraper registration
162
+ - `_LegacyDocumentScraperMetadataRegistration` - Legacy document scraper metadata registration
163
+ - `_DocumentScraperRegistration` - Document scraper registration
164
+ - `_DocumentScraperMetadataRegistration` - Document scraper metadata registration
165
+ - `_MarkdownScraperRegistration` - Markdown scraper registration
166
+ - `_MarkdownScraperMetadataRegistration` - Markdown scraper metadata registration
167
+ - `_MarkitdownScraperRegistration` - Markitdown scraper registration
168
+ - `_MarkitdownScraperMetadataRegistration` - Markitdown scraper metadata registration
169
+ - `_PdfScraperRegistration` - PDF scraper registration
170
+ - `_PdfScraperMetadataRegistration` - PDF scraper metadata registration
171
+ - `_WebsiteScraperRegistration` - Website scraper registration
172
+ - `_WebsiteScraperMetadataRegistration` - Website scraper metadata registration
173
+
107
174
 
108
175
  ---
109
176
 
package/esm/index.es.js CHANGED
@@ -13,9 +13,6 @@ import { io } from 'socket.io-client';
13
13
  import { Subject } from 'rxjs';
14
14
  import { spawn } from 'child_process';
15
15
  import JSZip from 'jszip';
16
- import parserHtml from 'prettier/parser-html';
17
- import parserMarkdown from 'prettier/parser-markdown';
18
- import { format } from 'prettier/standalone';
19
16
  import { parse, unparse } from 'papaparse';
20
17
  import { SHA256 } from 'crypto-js';
21
18
  import { lookup, extension } from 'mime-types';
@@ -48,7 +45,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
48
45
  * @generated
49
46
  * @see https://github.com/webgptorg/promptbook
50
47
  */
51
- const PROMPTBOOK_ENGINE_VERSION = '0.100.4-0';
48
+ const PROMPTBOOK_ENGINE_VERSION = '0.101.0-1';
52
49
  /**
53
50
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
54
51
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -739,6 +736,8 @@ function $getGlobalScope() {
739
736
  /**
740
737
  * Normalizes a text string to SCREAMING_CASE (all uppercase with underscores).
741
738
  *
739
+ * Note: [🔂] This function is idempotent.
740
+ *
742
741
  * @param text The text string to be converted to SCREAMING_CASE format.
743
742
  * @returns The normalized text in SCREAMING_CASE format.
744
743
  * @example 'HELLO_WORLD'
@@ -794,6 +793,8 @@ function normalizeTo_SCREAMING_CASE(text) {
794
793
  /**
795
794
  * Normalizes a text string to snake_case format.
796
795
  *
796
+ * Note: [🔂] This function is idempotent.
797
+ *
797
798
  * @param text The text string to be converted to snake_case format.
798
799
  * @returns The normalized text in snake_case format.
799
800
  * @example 'hello_world'
@@ -1506,6 +1507,7 @@ function checkSerializableAsJson(options) {
1506
1507
  /**
1507
1508
  * Creates a deep clone of the given object
1508
1509
  *
1510
+ * Note: [🔂] This function is idempotent.
1509
1511
  * Note: This method only works for objects that are fully serializable to JSON and do not contain functions, Dates, or special types.
1510
1512
  *
1511
1513
  * @param objectValue The object to clone.
@@ -1722,6 +1724,8 @@ function stringifyPipelineJson(pipeline) {
1722
1724
  /**
1723
1725
  * Removes emojis from a string and fix whitespaces
1724
1726
  *
1727
+ * Note: [🔂] This function is idempotent.
1728
+ *
1725
1729
  * @param text with emojis
1726
1730
  * @returns text without emojis
1727
1731
  * @public exported from `@promptbook/utils`
@@ -1794,6 +1798,7 @@ function isValidFilePath(filename) {
1794
1798
  /**
1795
1799
  * Tests if given string is valid URL.
1796
1800
  *
1801
+ * Note: [🔂] This function is idempotent.
1797
1802
  * Note: Dataurl are considered perfectly valid.
1798
1803
  * Note: There are two similar functions:
1799
1804
  * - `isValidUrl` which tests any URL
@@ -2067,6 +2072,8 @@ for (let i = 0; i < defaultDiacriticsRemovalMap.length; i++) {
2067
2072
  /**
2068
2073
  * Removes diacritic marks (accents) from characters in a string.
2069
2074
  *
2075
+ * Note: [🔂] This function is idempotent.
2076
+ *
2070
2077
  * @param input The string containing diacritics to be normalized.
2071
2078
  * @returns The string with diacritics removed or normalized.
2072
2079
  * @public exported from `@promptbook/utils`
@@ -2630,7 +2637,7 @@ const LLM_PROVIDER_PROFILES = {
2630
2637
  };
2631
2638
  /**
2632
2639
  * TODO: Refactor this - each profile must be alongside the provider definition
2633
- * TODO: [🕛] Unite `AvatarProfileProps`, `ChatParticipant`, `LlmExecutionTools` + `LlmToolsMetadata`
2640
+ * TODO: [🕛] Unite `AgentBasicInformation`, `ChatParticipant`, `LlmExecutionTools` + `LlmToolsMetadata`
2634
2641
  * Note: [💞] Ignore a discrepancy between file name and entity name
2635
2642
  */
2636
2643
 
@@ -2896,6 +2903,8 @@ function isValidJsonString(value /* <- [👨‍⚖️] */) {
2896
2903
  /**
2897
2904
  * Makes first letter of a string uppercase
2898
2905
  *
2906
+ * Note: [🔂] This function is idempotent.
2907
+ *
2899
2908
  * @public exported from `@promptbook/utils`
2900
2909
  */
2901
2910
  function capitalize(word) {
@@ -3020,6 +3029,7 @@ function countCharacters(text) {
3020
3029
  }
3021
3030
  /**
3022
3031
  * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
3032
+ * TODO: [🧠][✌️] Make some Promptbook-native token system
3023
3033
  */
3024
3034
 
3025
3035
  /**
@@ -3054,6 +3064,7 @@ function countLines(text) {
3054
3064
  }
3055
3065
  /**
3056
3066
  * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
3067
+ * TODO: [🧠][✌️] Make some Promptbook-native token system
3057
3068
  */
3058
3069
 
3059
3070
  /**
@@ -3068,6 +3079,7 @@ function countPages(text) {
3068
3079
  }
3069
3080
  /**
3070
3081
  * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
3082
+ * TODO: [🧠][✌️] Make some Promptbook-native token system
3071
3083
  */
3072
3084
 
3073
3085
  /**
@@ -3080,6 +3092,7 @@ function countParagraphs(text) {
3080
3092
  }
3081
3093
  /**
3082
3094
  * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
3095
+ * TODO: [🧠][✌️] Make some Promptbook-native token system
3083
3096
  */
3084
3097
 
3085
3098
  /**
@@ -3100,6 +3113,7 @@ function countSentences(text) {
3100
3113
  }
3101
3114
  /**
3102
3115
  * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
3116
+ * TODO: [🧠][✌️] Make some Promptbook-native token system
3103
3117
  */
3104
3118
 
3105
3119
  /**
@@ -3116,6 +3130,8 @@ function countWords(text) {
3116
3130
  }
3117
3131
  /**
3118
3132
  * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
3133
+ * TODO: [🧠][✌️] Make some Promptbook-native token system
3134
+ * TODO: [✌️] `countWords` should be just `splitWords(...).length`, and all other counters should use this pattern as well
3119
3135
  */
3120
3136
 
3121
3137
  /**
@@ -5216,8 +5232,18 @@ function validatePipelineString(pipelineString) {
5216
5232
  * @private withing the package because of HUGE size of prettier dependency
5217
5233
  */
5218
5234
  function prettifyMarkdown(content) {
5235
+ // In browser/Next.js environments, just return the original content
5236
+ // since prettier parsers are not available and would cause bundling issues
5237
+ if (typeof window !== 'undefined') {
5238
+ return content;
5239
+ }
5219
5240
  try {
5220
- return format(content, {
5241
+ // Use dynamic require to avoid static imports that cause bundling issues
5242
+ // This will only work in Node.js environments
5243
+ const prettierStandalone = eval('require')('prettier/standalone');
5244
+ const parserMarkdown = eval('require')('prettier/parser-markdown');
5245
+ const parserHtml = eval('require')('prettier/parser-html');
5246
+ return prettierStandalone.format(content, {
5221
5247
  parser: 'markdown',
5222
5248
  plugins: [parserMarkdown, parserHtml],
5223
5249
  // TODO: DRY - make some import or auto-copy of .prettierrc
@@ -8925,6 +8951,7 @@ const EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRA
8925
8951
  /**
8926
8952
  * Function parseNumber will parse number from string
8927
8953
  *
8954
+ * Note: [🔂] This function is idempotent.
8928
8955
  * Unlike Number.parseInt, Number.parseFloat it will never ever result in NaN
8929
8956
  * Note: it also works only with decimal numbers
8930
8957
  *
@@ -9187,6 +9214,7 @@ function normalizeTo_camelCase(text, _isFirstLetterCapital = false) {
9187
9214
  /**
9188
9215
  * Removes quotes from a string
9189
9216
  *
9217
+ * Note: [🔂] This function is idempotent.
9190
9218
  * Tip: This is very useful for post-processing of the result of the LLM model
9191
9219
  * Note: This function removes only the same quotes from the beginning and the end of the string
9192
9220
  * Note: There are two similar functions:
@@ -12039,7 +12067,9 @@ function renderPromptbookMermaid(pipelineJson, options) {
12039
12067
  */
12040
12068
 
12041
12069
  /**
12042
- * Makes first letter of a string uppercase
12070
+ * Makes first letter of a string lowercase
12071
+ *
12072
+ * Note: [🔂] This function is idempotent.
12043
12073
  *
12044
12074
  * @public exported from `@promptbook/utils`
12045
12075
  */
@@ -12109,6 +12139,8 @@ function normalizeTo_PascalCase(text) {
12109
12139
  /**
12110
12140
  * Take every whitespace (space, new line, tab) and replace it with a single space
12111
12141
  *
12142
+ * Note: [🔂] This function is idempotent.
12143
+ *
12112
12144
  * @public exported from `@promptbook/utils`
12113
12145
  */
12114
12146
  function normalizeWhitespaces(sentence) {
@@ -12129,6 +12161,7 @@ function suffixUrl(value, suffix) {
12129
12161
  /**
12130
12162
  * Function trimCodeBlock will trim starting and ending code block from the string if it is present.
12131
12163
  *
12164
+ * Note: [🔂] This function is idempotent.
12132
12165
  * Note: This is useful for post-processing of the result of the chat LLM model
12133
12166
  * when the model wraps the result in the (markdown) code block.
12134
12167
  *
@@ -13366,6 +13399,8 @@ function createMarkdownChart(options) {
13366
13399
  * Function escapeMarkdownBlock will escape markdown block if needed
13367
13400
  * It is useful when you want have block in block
13368
13401
  *
13402
+ * Note: [🔂] This function is idempotent.
13403
+ *
13369
13404
  * @public exported from `@promptbook/markdown-utils`
13370
13405
  */
13371
13406
  function escapeMarkdownBlock(value) {