@promptbook/node 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 +49 -1
- package/esm/index.es.js +32 -6
- 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 +2 -2
- package/umd/index.umd.js +37 -10
- package/umd/index.umd.js.map +1 -1
package/README.md
CHANGED
@@ -48,9 +48,57 @@ npm i ptbk
|
|
48
48
|
npm install @promptbook/node
|
49
49
|
```
|
50
50
|
|
51
|
-
|
51
|
+
The Node.js package provides Node.js-specific functionality for Promptbook, including filesystem operations, command execution, and automatic provider configuration. It serves as the bridge between Promptbook's core functionality and Node.js runtime capabilities.
|
52
52
|
|
53
|
+
## 🎯 Purpose and Motivation
|
53
54
|
|
55
|
+
This package extends Promptbook's core functionality with Node.js-specific features that are essential for server-side and desktop applications. It provides filesystem access, command execution, automatic LLM provider detection, and other Node.js runtime capabilities that enable full-featured Promptbook applications.
|
56
|
+
|
57
|
+
## 🔧 High-Level Functionality
|
58
|
+
|
59
|
+
The package provides Node.js-specific integrations and utilities:
|
60
|
+
- **Filesystem Operations**: Read promptbooks from directories and manage file-based collections
|
61
|
+
- **Automatic Provider Setup**: Detect and configure LLM providers from environment variables
|
62
|
+
- **Command Execution**: Execute system commands and scripts
|
63
|
+
- **Knowledge Scraping**: Node.js-specific scrapers for various content sources
|
64
|
+
- **File-based Storage**: Persistent storage using the filesystem
|
65
|
+
- **Environment Integration**: Seamless integration with Node.js environment and tooling
|
66
|
+
|
67
|
+
## ✨ Key Features
|
68
|
+
|
69
|
+
- 📁 **Directory-based Collections** - Load promptbook collections from filesystem directories
|
70
|
+
- 🔧 **Auto-configuration** - Automatically detect and configure LLM providers from environment
|
71
|
+
- 💾 **File Storage** - Persistent caching and storage using the filesystem
|
72
|
+
- 🛠️ **Command Execution** - Execute system commands and scripts from promptbooks
|
73
|
+
- 🌐 **Knowledge Scraping** - Scrape content from files, websites, and other sources
|
74
|
+
- 🔌 **Provider Detection** - Automatically discover available LLM providers
|
75
|
+
- 📊 **Executable Management** - Manage and execute external tools and scripts
|
76
|
+
- 🚀 **Performance Optimization** - File-based caching for improved performance
|
77
|
+
|
78
|
+
## 📦 Exported Entities
|
79
|
+
|
80
|
+
### Version Information
|
81
|
+
- `BOOK_LANGUAGE_VERSION` - Current book language version
|
82
|
+
- `PROMPTBOOK_ENGINE_VERSION` - Current engine version
|
83
|
+
|
84
|
+
### Collection Management
|
85
|
+
- `createCollectionFromDirectory` - Create promptbook collection from filesystem directory
|
86
|
+
|
87
|
+
### Provider Configuration
|
88
|
+
- `$provideExecutablesForNode` - Provide executable tools for Node.js environment
|
89
|
+
- `$provideExecutionToolsForNode` - Auto-configure all execution tools from environment
|
90
|
+
- `$provideLlmToolsConfigurationFromEnv` - Create LLM tools configuration from environment variables
|
91
|
+
- `$provideLlmToolsFromEnv` - Create LLM tools from environment variables
|
92
|
+
- `$provideFilesystemForNode` - Provide filesystem access for Node.js
|
93
|
+
- `$provideScrapersForNode` - Provide knowledge scrapers for Node.js environment
|
94
|
+
- `$provideScriptingForNode` - Provide scripting capabilities for Node.js
|
95
|
+
|
96
|
+
### Storage
|
97
|
+
- `FileCacheStorage` - File-based cache storage implementation
|
98
|
+
|
99
|
+
### Command Execution
|
100
|
+
- `$execCommand` - Execute single system command
|
101
|
+
- `$execCommands` - Execute multiple system commands
|
54
102
|
|
55
103
|
> 💡 This package does not make sense on its own, look at [all promptbook packages](#-packages) or just install all by `npm i ptbk`
|
56
104
|
|
package/esm/index.es.js
CHANGED
@@ -3,9 +3,6 @@ import { stat, access, constants, readFile, writeFile, readdir, mkdir, unlink }
|
|
3
3
|
import { basename, join, dirname, isAbsolute, relative } from 'path';
|
4
4
|
import spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
|
5
5
|
import JSZip from 'jszip';
|
6
|
-
import parserHtml from 'prettier/parser-html';
|
7
|
-
import parserMarkdown from 'prettier/parser-markdown';
|
8
|
-
import { format } from 'prettier/standalone';
|
9
6
|
import { randomBytes } from 'crypto';
|
10
7
|
import { Subject } from 'rxjs';
|
11
8
|
import { forTime } from 'waitasecond';
|
@@ -31,7 +28,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
31
28
|
* @generated
|
32
29
|
* @see https://github.com/webgptorg/promptbook
|
33
30
|
*/
|
34
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.101.0-
|
31
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.101.0-2';
|
35
32
|
/**
|
36
33
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
37
34
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
@@ -595,6 +592,7 @@ function checkSerializableAsJson(options) {
|
|
595
592
|
/**
|
596
593
|
* Creates a deep clone of the given object
|
597
594
|
*
|
595
|
+
* Note: [🔂] This function is idempotent.
|
598
596
|
* Note: This method only works for objects that are fully serializable to JSON and do not contain functions, Dates, or special types.
|
599
597
|
*
|
600
598
|
* @param objectValue The object to clone.
|
@@ -789,6 +787,7 @@ function isValidPromptbookVersion(version) {
|
|
789
787
|
/**
|
790
788
|
* Tests if given string is valid URL.
|
791
789
|
*
|
790
|
+
* Note: [🔂] This function is idempotent.
|
792
791
|
* Note: Dataurl are considered perfectly valid.
|
793
792
|
* Note: There are two similar functions:
|
794
793
|
* - `isValidUrl` which tests any URL
|
@@ -1299,8 +1298,18 @@ function validatePipelineString(pipelineString) {
|
|
1299
1298
|
* @private withing the package because of HUGE size of prettier dependency
|
1300
1299
|
*/
|
1301
1300
|
function prettifyMarkdown(content) {
|
1301
|
+
// In browser/Next.js environments, just return the original content
|
1302
|
+
// since prettier parsers are not available and would cause bundling issues
|
1303
|
+
if (typeof window !== 'undefined') {
|
1304
|
+
return content;
|
1305
|
+
}
|
1302
1306
|
try {
|
1303
|
-
|
1307
|
+
// Use dynamic require to avoid static imports that cause bundling issues
|
1308
|
+
// This will only work in Node.js environments
|
1309
|
+
const prettierStandalone = eval('require')('prettier/standalone');
|
1310
|
+
const parserMarkdown = eval('require')('prettier/parser-markdown');
|
1311
|
+
const parserHtml = eval('require')('prettier/parser-html');
|
1312
|
+
return prettierStandalone.format(content, {
|
1304
1313
|
parser: 'markdown',
|
1305
1314
|
plugins: [parserMarkdown, parserHtml],
|
1306
1315
|
// TODO: DRY - make some import or auto-copy of .prettierrc
|
@@ -1328,6 +1337,8 @@ function prettifyMarkdown(content) {
|
|
1328
1337
|
/**
|
1329
1338
|
* Makes first letter of a string uppercase
|
1330
1339
|
*
|
1340
|
+
* Note: [🔂] This function is idempotent.
|
1341
|
+
*
|
1331
1342
|
* @public exported from `@promptbook/utils`
|
1332
1343
|
*/
|
1333
1344
|
function capitalize(word) {
|
@@ -3831,6 +3842,8 @@ for (let i = 0; i < defaultDiacriticsRemovalMap.length; i++) {
|
|
3831
3842
|
/**
|
3832
3843
|
* Removes diacritic marks (accents) from characters in a string.
|
3833
3844
|
*
|
3845
|
+
* Note: [🔂] This function is idempotent.
|
3846
|
+
*
|
3834
3847
|
* @param input The string containing diacritics to be normalized.
|
3835
3848
|
* @returns The string with diacritics removed or normalized.
|
3836
3849
|
* @public exported from `@promptbook/utils`
|
@@ -5360,6 +5373,8 @@ function $getGlobalScope() {
|
|
5360
5373
|
/**
|
5361
5374
|
* Normalizes a text string to SCREAMING_CASE (all uppercase with underscores).
|
5362
5375
|
*
|
5376
|
+
* Note: [🔂] This function is idempotent.
|
5377
|
+
*
|
5363
5378
|
* @param text The text string to be converted to SCREAMING_CASE format.
|
5364
5379
|
* @returns The normalized text in SCREAMING_CASE format.
|
5365
5380
|
* @example 'HELLO_WORLD'
|
@@ -5415,6 +5430,8 @@ function normalizeTo_SCREAMING_CASE(text) {
|
|
5415
5430
|
/**
|
5416
5431
|
* Normalizes a text string to snake_case format.
|
5417
5432
|
*
|
5433
|
+
* Note: [🔂] This function is idempotent.
|
5434
|
+
*
|
5418
5435
|
* @param text The text string to be converted to snake_case format.
|
5419
5436
|
* @returns The normalized text in snake_case format.
|
5420
5437
|
* @example 'hello_world'
|
@@ -5725,6 +5742,8 @@ function mimeTypeToExtension(value) {
|
|
5725
5742
|
/**
|
5726
5743
|
* Removes emojis from a string and fix whitespaces
|
5727
5744
|
*
|
5745
|
+
* Note: [🔂] This function is idempotent.
|
5746
|
+
*
|
5728
5747
|
* @param text with emojis
|
5729
5748
|
* @returns text without emojis
|
5730
5749
|
* @public exported from `@promptbook/utils`
|
@@ -6814,6 +6833,7 @@ const EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRA
|
|
6814
6833
|
/**
|
6815
6834
|
* Function parseNumber will parse number from string
|
6816
6835
|
*
|
6836
|
+
* Note: [🔂] This function is idempotent.
|
6817
6837
|
* Unlike Number.parseInt, Number.parseFloat it will never ever result in NaN
|
6818
6838
|
* Note: it also works only with decimal numbers
|
6819
6839
|
*
|
@@ -7076,6 +7096,7 @@ function normalizeTo_camelCase(text, _isFirstLetterCapital = false) {
|
|
7076
7096
|
/**
|
7077
7097
|
* Removes quotes from a string
|
7078
7098
|
*
|
7099
|
+
* Note: [🔂] This function is idempotent.
|
7079
7100
|
* Tip: This is very useful for post-processing of the result of the LLM model
|
7080
7101
|
* Note: This function removes only the same quotes from the beginning and the end of the string
|
7081
7102
|
* Note: There are two similar functions:
|
@@ -10698,7 +10719,9 @@ new Function(`
|
|
10698
10719
|
*/
|
10699
10720
|
|
10700
10721
|
/**
|
10701
|
-
* Makes first letter of a string
|
10722
|
+
* Makes first letter of a string lowercase
|
10723
|
+
*
|
10724
|
+
* Note: [🔂] This function is idempotent.
|
10702
10725
|
*
|
10703
10726
|
* @public exported from `@promptbook/utils`
|
10704
10727
|
*/
|
@@ -10768,6 +10791,8 @@ function normalizeTo_PascalCase(text) {
|
|
10768
10791
|
/**
|
10769
10792
|
* Take every whitespace (space, new line, tab) and replace it with a single space
|
10770
10793
|
*
|
10794
|
+
* Note: [🔂] This function is idempotent.
|
10795
|
+
*
|
10771
10796
|
* @public exported from `@promptbook/utils`
|
10772
10797
|
*/
|
10773
10798
|
function normalizeWhitespaces(sentence) {
|
@@ -10811,6 +10836,7 @@ function isSerializableAsJson(value) {
|
|
10811
10836
|
/**
|
10812
10837
|
* Function trimCodeBlock will trim starting and ending code block from the string if it is present.
|
10813
10838
|
*
|
10839
|
+
* Note: [🔂] This function is idempotent.
|
10814
10840
|
* Note: This is useful for post-processing of the result of the chat LLM model
|
10815
10841
|
* when the model wraps the result in the (markdown) code block.
|
10816
10842
|
*
|