@promptbook/utils 0.101.0-2 โ†’ 0.101.0-3

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 CHANGED
@@ -48,9 +48,34 @@ npm i ptbk
48
48
  npm install @promptbook/utils
49
49
  ```
50
50
 
51
- Utility functions used in the library, but also useful for individual use in pre and post-processing of LLM inputs and outputs.
51
+ Comprehensive utility functions for text processing, validation, normalization, and LLM input/output handling in the Promptbook ecosystem.
52
52
 
53
- Here is an overview of the functions that can be exported from the `@promptbook/utils` package and used in your own projects:
53
+ ## ๐ŸŽฏ Purpose and Motivation
54
+
55
+ The utils package provides a rich collection of utility functions that are essential for working with LLM inputs and outputs. It handles common tasks like text normalization, parameter templating, validation, and postprocessing, eliminating the need to implement these utilities from scratch in every promptbook application.
56
+
57
+ ## ๐Ÿ”ง High-Level Functionality
58
+
59
+ This package offers utilities across multiple domains:
60
+
61
+ - **Text Processing**: Counting, splitting, and analyzing text content
62
+ - **Template System**: Secure parameter substitution and prompt formatting
63
+ - **Normalization**: Converting text to various naming conventions and formats
64
+ - **Validation**: Comprehensive validation for URLs, emails, file paths, and more
65
+ - **Serialization**: JSON handling, deep cloning, and object manipulation
66
+ - **Environment Detection**: Runtime environment identification utilities
67
+ - **Format Parsing**: Support for CSV, JSON, XML validation and parsing
68
+
69
+ ## โœจ Key Features
70
+
71
+ - ๐Ÿ”’ **Secure Templating** - Prompt injection protection with template functions
72
+ - ๐Ÿ“Š **Text Analysis** - Count words, sentences, paragraphs, pages, and characters
73
+ - ๐Ÿ”„ **Case Conversion** - Support for kebab-case, camelCase, PascalCase, SCREAMING_CASE
74
+ - โœ… **Comprehensive Validation** - Email, URL, file path, UUID, and format validators
75
+ - ๐Ÿงน **Text Cleaning** - Remove emojis, quotes, diacritics, and normalize whitespace
76
+ - ๐Ÿ“ฆ **Serialization Tools** - Deep cloning, JSON export, and serialization checking
77
+ - ๐ŸŒ **Environment Aware** - Detect browser, Node.js, Jest, and Web Worker environments
78
+ - ๐ŸŽฏ **LLM Optimized** - Functions specifically designed for LLM input/output processing
54
79
 
55
80
  ## Simple templating
56
81
 
@@ -184,133 +209,149 @@ import { unwrapResult } from '@promptbook/utils';
184
209
  unwrapResult('Best greeting for the user is "Hi Pavol!"'); // 'Hi Pavol!'
185
210
  ```
186
211
 
187
- ## Misc
188
-
189
- ## ๐Ÿ“ฆ Complete List of Exported Entities
212
+ ## ๐Ÿ“ฆ Exported Entities
190
213
 
191
214
  ### Version Information
192
- - `BOOK_LANGUAGE_VERSION` - Current book language version
193
- - `PROMPTBOOK_ENGINE_VERSION` - Current engine version
215
+
216
+ - `BOOK_LANGUAGE_VERSION` - Current book language version
217
+ - `PROMPTBOOK_ENGINE_VERSION` - Current engine version
194
218
 
195
219
  ### Configuration Constants
196
- - `VALUE_STRINGS` - Standard value strings
197
- - `SMALL_NUMBER` - Small number constant
220
+
221
+ - `VALUE_STRINGS` - Standard value strings
222
+ - `SMALL_NUMBER` - Small number constant
198
223
 
199
224
  ### Visualization
200
- - `renderPromptbookMermaid` - Render promptbook as Mermaid diagram
225
+
226
+ - `renderPromptbookMermaid` - Render promptbook as Mermaid diagram
201
227
 
202
228
  ### Error Handling
203
- - `deserializeError` - Deserialize error objects
204
- - `serializeError` - Serialize error objects
229
+
230
+ - `deserializeError` - Deserialize error objects
231
+ - `serializeError` - Serialize error objects
205
232
 
206
233
  ### Async Utilities
207
- - `forEachAsync` - Async forEach implementation
234
+
235
+ - `forEachAsync` - Async forEach implementation
208
236
 
209
237
  ### Format Validation
210
- - `isValidCsvString` - Validate CSV string format
211
- - `isValidJsonString` - Validate JSON string format
212
- - `jsonParse` - Safe JSON parsing
213
- - `isValidXmlString` - Validate XML string format
238
+
239
+ - `isValidCsvString` - Validate CSV string format
240
+ - `isValidJsonString` - Validate JSON string format
241
+ - `jsonParse` - Safe JSON parsing
242
+ - `isValidXmlString` - Validate XML string format
214
243
 
215
244
  ### Template Functions
216
- - `prompt` - Template tag for secure prompt formatting
217
- - `promptTemplate` - Alias for prompt template tag
245
+
246
+ - `prompt` - Template tag for secure prompt formatting
247
+ - `promptTemplate` - Alias for prompt template tag
218
248
 
219
249
  ### Environment Detection
220
- - `$getCurrentDate` - Get current date (side effect)
221
- - `$isRunningInBrowser` - Check if running in browser
222
- - `$isRunningInJest` - Check if running in Jest
223
- - `$isRunningInNode` - Check if running in Node.js
224
- - `$isRunningInWebWorker` - Check if running in Web Worker
250
+
251
+ - `$getCurrentDate` - Get current date (side effect)
252
+ - `$isRunningInBrowser` - Check if running in browser
253
+ - `$isRunningInJest` - Check if running in Jest
254
+ - `$isRunningInNode` - Check if running in Node.js
255
+ - `$isRunningInWebWorker` - Check if running in Web Worker
225
256
 
226
257
  ### Text Counting and Analysis
227
- - `CHARACTERS_PER_STANDARD_LINE` - Characters per standard line constant
228
- - `LINES_PER_STANDARD_PAGE` - Lines per standard page constant
229
- - `countCharacters` - Count characters in text
230
- - `countLines` - Count lines in text
231
- - `countPages` - Count pages in text
232
- - `countParagraphs` - Count paragraphs in text
233
- - `splitIntoSentences` - Split text into sentences
234
- - `countSentences` - Count sentences in text
235
- - `countWords` - Count words in text
236
- - `CountUtils` - Utility object with all counting functions
258
+
259
+ - `CHARACTERS_PER_STANDARD_LINE` - Characters per standard line constant
260
+ - `LINES_PER_STANDARD_PAGE` - Lines per standard page constant
261
+ - `countCharacters` - Count characters in text
262
+ - `countLines` - Count lines in text
263
+ - `countPages` - Count pages in text
264
+ - `countParagraphs` - Count paragraphs in text
265
+ - `splitIntoSentences` - Split text into sentences
266
+ - `countSentences` - Count sentences in text
267
+ - `countWords` - Count words in text
268
+ - `CountUtils` - Utility object with all counting functions
237
269
 
238
270
  ### Text Normalization
239
- - `capitalize` - Capitalize first letter
240
- - `decapitalize` - Decapitalize first letter
241
- - `DIACRITIC_VARIANTS_LETTERS` - Diacritic variants mapping
242
- - `string_keyword` - Keyword string type
243
- - `Keywords` - Keywords type
244
- - `isValidKeyword` - Validate keyword format
245
- - `nameToUriPart` - Convert name to URI part
246
- - `nameToUriParts` - Convert name to URI parts
247
- - `string_kebab_case` - Kebab case string type
248
- - `normalizeToKebabCase` - Convert to kebab-case
249
- - `string_camelCase` - Camel case string type
250
- - `normalizeTo_camelCase` - Convert to camelCase
251
- - `string_PascalCase` - Pascal case string type
252
- - `normalizeTo_PascalCase` - Convert to PascalCase
253
- - `string_SCREAMING_CASE` - Screaming case string type
254
- - `normalizeTo_SCREAMING_CASE` - Convert to SCREAMING_CASE
255
- - `normalizeTo_snake_case` - Convert to snake_case
256
- - `normalizeWhitespaces` - Normalize whitespace characters
257
- - `orderJson` - Order JSON object properties
258
- - `parseKeywords` - Parse keywords from input
259
- - `parseKeywordsFromString` - Parse keywords from string
260
- - `removeDiacritics` - Remove diacritic marks
261
- - `searchKeywords` - Search within keywords
262
- - `suffixUrl` - Add suffix to URL
263
- - `titleToName` - Convert title to name format
271
+
272
+ - `capitalize` - Capitalize first letter
273
+ - `decapitalize` - Decapitalize first letter
274
+ - `DIACRITIC_VARIANTS_LETTERS` - Diacritic variants mapping
275
+ - `string_keyword` - Keyword string type (type)
276
+ - `Keywords` - Keywords type (type)
277
+ - `isValidKeyword` - Validate keyword format
278
+ - `nameToUriPart` - Convert name to URI part
279
+ - `nameToUriParts` - Convert name to URI parts
280
+ - `string_kebab_case` - Kebab case string type (type)
281
+ - `normalizeToKebabCase` - Convert to kebab-case
282
+ - `string_camelCase` - Camel case string type (type)
283
+ - `normalizeTo_camelCase` - Convert to camelCase
284
+ - `string_PascalCase` - Pascal case string type (type)
285
+ - `normalizeTo_PascalCase` - Convert to PascalCase
286
+ - `string_SCREAMING_CASE` - Screaming case string type (type)
287
+ - `normalizeTo_SCREAMING_CASE` - Convert to SCREAMING_CASE
288
+ - `normalizeTo_snake_case` - Convert to snake_case
289
+ - `normalizeWhitespaces` - Normalize whitespace characters
290
+ - `orderJson` - Order JSON object properties
291
+ - `parseKeywords` - Parse keywords from input
292
+ - `parseKeywordsFromString` - Parse keywords from string
293
+ - `removeDiacritics` - Remove diacritic marks
294
+ - `searchKeywords` - Search within keywords
295
+ - `suffixUrl` - Add suffix to URL
296
+ - `titleToName` - Convert title to name format
264
297
 
265
298
  ### Text Organization
266
- - `spaceTrim` - Trim spaces while preserving structure
299
+
300
+ - `spaceTrim` - Trim spaces while preserving structure
267
301
 
268
302
  ### Parameter Processing
269
- - `extractParameterNames` - Extract parameter names from template
270
- - `numberToString` - Convert number to string
271
- - `templateParameters` - Replace template parameters
272
- - `valueToString` - Convert value to string
303
+
304
+ - `extractParameterNames` - Extract parameter names from template
305
+ - `numberToString` - Convert number to string
306
+ - `templateParameters` - Replace template parameters
307
+ - `valueToString` - Convert value to string
273
308
 
274
309
  ### Parsing Utilities
275
- - `parseNumber` - Parse number from string
310
+
311
+ - `parseNumber` - Parse number from string
276
312
 
277
313
  ### Text Processing
278
- - `removeEmojis` - Remove emoji characters
279
- - `removeQuotes` - Remove quote characters
314
+
315
+ - `removeEmojis` - Remove emoji characters
316
+ - `removeQuotes` - Remove quote characters
280
317
 
281
318
  ### Serialization
282
- - `$deepFreeze` - Deep freeze object (side effect)
283
- - `checkSerializableAsJson` - Check if serializable as JSON
284
- - `clonePipeline` - Clone pipeline object
285
- - `deepClone` - Deep clone object
286
- - `exportJson` - Export object as JSON
287
- - `isSerializableAsJson` - Check if object is JSON serializable
288
- - `jsonStringsToJsons` - Convert JSON strings to objects
319
+
320
+ - `$deepFreeze` - Deep freeze object (side effect)
321
+ - `checkSerializableAsJson` - Check if serializable as JSON
322
+ - `clonePipeline` - Clone pipeline object
323
+ - `deepClone` - Deep clone object
324
+ - `exportJson` - Export object as JSON
325
+ - `isSerializableAsJson` - Check if object is JSON serializable
326
+ - `jsonStringsToJsons` - Convert JSON strings to objects
289
327
 
290
328
  ### Set Operations
291
- - `difference` - Set difference operation
292
- - `intersection` - Set intersection operation
293
- - `union` - Set union operation
329
+
330
+ - `difference` - Set difference operation
331
+ - `intersection` - Set intersection operation
332
+ - `union` - Set union operation
294
333
 
295
334
  ### Code Processing
296
- - `trimCodeBlock` - Trim code block formatting
297
- - `trimEndOfCodeBlock` - Trim end of code block
298
- - `unwrapResult` - Extract result from wrapped output
335
+
336
+ - `trimCodeBlock` - Trim code block formatting
337
+ - `trimEndOfCodeBlock` - Trim end of code block
338
+ - `unwrapResult` - Extract result from wrapped output
299
339
 
300
340
  ### Validation
301
- - `isValidEmail` - Validate email address format
302
- - `isRootPath` - Check if path is root path
303
- - `isValidFilePath` - Validate file path format
304
- - `isValidJavascriptName` - Validate JavaScript identifier
305
- - `isValidPromptbookVersion` - Validate promptbook version
306
- - `isValidSemanticVersion` - Validate semantic version
307
- - `isHostnameOnPrivateNetwork` - Check if hostname is on private network
308
- - `isUrlOnPrivateNetwork` - Check if URL is on private network
309
- - `isValidPipelineUrl` - Validate pipeline URL format
310
- - `isValidUrl` - Validate URL format
311
- - `isValidUuid` - Validate UUID format
312
-
313
- See also the documentation for all the functions in the `@promptbook/utils` package, every function is documented by jsdoc, typed by typescript and tested by jest.
341
+
342
+ - `isValidEmail` - Validate email address format
343
+ - `isRootPath` - Check if path is root path
344
+ - `isValidFilePath` - Validate file path format
345
+ - `isValidJavascriptName` - Validate JavaScript identifier
346
+ - `isValidPromptbookVersion` - Validate promptbook version
347
+ - `isValidSemanticVersion` - Validate semantic version
348
+ - `isHostnameOnPrivateNetwork` - Check if hostname is on private network
349
+ - `isUrlOnPrivateNetwork` - Check if URL is on private network
350
+ - `isValidPipelineUrl` - Validate pipeline URL format
351
+ - `isValidUrl` - Validate URL format
352
+ - `isValidUuid` - Validate UUID format
353
+
354
+ > ๐Ÿ’ก This package provides utility functions for promptbook applications. For the core functionality, see [@promptbook/core](#-packages) or install all packages with `npm i ptbk`
314
355
 
315
356
 
316
357
  ---
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.101.0-2';
19
+ const PROMPTBOOK_ENGINE_VERSION = '0.101.0-3';
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
@@ -119,4 +119,24 @@ export type ChatProps = {
119
119
  * Keys should match ChatMessage.from values (e.g., 'USER', 'AGENT_{id}', etc.)
120
120
  */
121
121
  readonly participants?: ReadonlyArray<ChatParticipant>;
122
+ /**
123
+ * Optional callback for handling user feedback on messages
124
+ * When provided, star rating buttons (1-5 stars) will be displayed next to each message
125
+ *
126
+ * @param feedback - Object containing the feedback data
127
+ * @param feedback.message - The message being rated
128
+ * @param feedback.rating - Star rating from 1 to 5
129
+ * @param feedback.textRating - Optional text feedback/note from user
130
+ * @param feedback.chatThread - Complete chat thread as string
131
+ * @param feedback.expectedAnswer - Optional expected answer provided by user
132
+ * @param feedback.url - Current page URL where feedback was given
133
+ */
134
+ onFeedback?(feedback: {
135
+ message: ChatMessage;
136
+ rating: number;
137
+ textRating: string;
138
+ chatThread: string;
139
+ expectedAnswer: string | null;
140
+ url: string;
141
+ }): Promisable<void>;
122
142
  };
@@ -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.101.0-1`).
18
+ * It follows semantic versioning (e.g., `0.101.0-2`).
19
19
  *
20
20
  * @generated
21
21
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/utils",
3
- "version": "0.101.0-2",
3
+ "version": "0.101.0-3",
4
4
  "description": "Promptbook: Run AI apps in plain human language across multiple models and platforms",
5
5
  "private": false,
6
6
  "sideEffects": false,
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-2';
25
+ const PROMPTBOOK_ENGINE_VERSION = '0.101.0-3';
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