@promptbook/node 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.
- package/README.md +49 -1
- package/esm/index.es.js +40 -7
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/components.index.d.ts +4 -0
- package/esm/typings/src/_packages/core.index.d.ts +4 -2
- package/esm/typings/src/_packages/markdown-utils.index.d.ts +14 -0
- package/esm/typings/src/_packages/types.index.d.ts +4 -6
- package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +21 -0
- package/esm/typings/src/book-2.0/{commitments/_misc → agent-source}/AgentModelRequirements.d.ts +1 -1
- package/esm/typings/src/book-2.0/{commitments/_misc → agent-source}/AgentSourceParseResult.d.ts +3 -1
- package/esm/typings/src/book-2.0/{commitments/_misc → agent-source}/createAgentModelRequirements.d.ts +2 -2
- package/esm/typings/src/book-2.0/{commitments/_misc → agent-source}/createAgentModelRequirementsWithCommitments.d.ts +3 -3
- package/esm/typings/src/book-2.0/{commitments/_misc → agent-source}/createCommitmentRegex.d.ts +2 -2
- package/esm/typings/src/book-2.0/agent-source/extractMetaLinks.d.ts +8 -0
- package/esm/typings/src/book-2.0/agent-source/parseAgentSource.d.ts +4 -19
- package/esm/typings/src/book-2.0/agent-source/parseAgentSourceWithCommitments.d.ts +9 -0
- package/esm/typings/src/book-2.0/commitments/ACTION/ACTION.d.ts +1 -1
- package/esm/typings/src/book-2.0/commitments/FORMAT/FORMAT.d.ts +1 -1
- package/esm/typings/src/book-2.0/commitments/KNOWLEDGE/KNOWLEDGE.d.ts +1 -1
- package/esm/typings/src/book-2.0/commitments/META_IMAGE/META_IMAGE.d.ts +1 -1
- package/esm/typings/src/book-2.0/commitments/META_LINK/META_LINK.d.ts +1 -1
- package/esm/typings/src/book-2.0/commitments/MODEL/MODEL.d.ts +1 -1
- package/esm/typings/src/book-2.0/commitments/NOTE/NOTE.d.ts +1 -1
- package/esm/typings/src/book-2.0/commitments/PERSONA/PERSONA.d.ts +1 -1
- package/esm/typings/src/book-2.0/commitments/RULE/RULE.d.ts +1 -1
- package/esm/typings/src/book-2.0/commitments/SAMPLE/SAMPLE.d.ts +1 -1
- package/esm/typings/src/book-2.0/commitments/STYLE/STYLE.d.ts +1 -1
- package/esm/typings/src/book-2.0/commitments/_base/BaseCommitmentDefinition.d.ts +1 -1
- package/esm/typings/src/book-2.0/commitments/_base/CommitmentDefinition.d.ts +1 -1
- package/esm/typings/src/book-2.0/commitments/_base/NotYetImplementedCommitmentDefinition.d.ts +1 -1
- package/esm/typings/src/book-2.0/commitments/{_misc → _base}/ParsedCommitment.d.ts +1 -1
- package/esm/typings/src/book-2.0/commitments/_base/createEmptyAgentModelRequirements.d.ts +1 -1
- package/esm/typings/src/book-2.0/utils/extractAgentMetadata.d.ts +17 -0
- package/esm/typings/src/book-2.0/utils/extractProfileImageFromSystemMessage.d.ts +12 -0
- package/esm/typings/src/book-2.0/utils/generateGravatarUrl.d.ts +10 -0
- package/esm/typings/src/book-2.0/utils/generatePlaceholderAgentProfileImageUrl.d.ts +10 -0
- package/esm/typings/src/book-components/AvatarProfile/AvatarChip/AvatarChip.d.ts +1 -1
- package/esm/typings/src/book-components/AvatarProfile/AvatarProfile/AvatarProfile.d.ts +2 -8
- package/esm/typings/src/book-components/Chat/Chat/ChatProps.d.ts +6 -0
- package/esm/typings/src/book-components/Chat/examples/ChatMarkdownDemo.d.ts +16 -0
- package/esm/typings/src/book-components/Chat/types/ChatParticipant.d.ts +1 -1
- 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/llm-providers/_common/profiles/llmProviderProfiles.d.ts +1 -1
- package/esm/typings/src/utils/expectation-counters/countCharacters.d.ts +2 -1
- package/esm/typings/src/utils/expectation-counters/countLines.d.ts +2 -1
- package/esm/typings/src/utils/expectation-counters/countPages.d.ts +2 -1
- package/esm/typings/src/utils/expectation-counters/countParagraphs.d.ts +2 -1
- package/esm/typings/src/utils/expectation-counters/countSentences.d.ts +1 -0
- package/esm/typings/src/utils/expectation-counters/countWords.d.ts +3 -1
- package/esm/typings/src/utils/markdown/escapeMarkdownBlock.d.ts +2 -0
- package/esm/typings/src/utils/markdown/humanizeAiText.d.ts +13 -0
- package/esm/typings/src/utils/markdown/humanizeAiText.test.d.ts +1 -0
- package/esm/typings/src/utils/markdown/humanizeAiTextEllipsis.d.ts +13 -0
- package/esm/typings/src/utils/markdown/humanizeAiTextEmdashed.d.ts +13 -0
- package/esm/typings/src/utils/markdown/humanizeAiTextQuotes.d.ts +13 -0
- package/esm/typings/src/utils/markdown/humanizeAiTextWhitespace.d.ts +13 -0
- package/esm/typings/src/utils/markdown/prettifyMarkdown.d.ts +8 -0
- package/esm/typings/src/utils/markdown/promptbookifyAiText.d.ts +12 -0
- package/esm/typings/src/utils/markdown/promptbookifyAiText.test.d.ts +1 -0
- package/esm/typings/src/utils/markdown/removeMarkdownLinks.d.ts +11 -0
- package/esm/typings/src/utils/markdown/removeMarkdownLinks.test.d.ts +4 -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 +45 -11
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/book-2.0/commitments/_misc/parseAgentSourceWithCommitments.d.ts +0 -24
- package/esm/typings/src/book-2.0/utils/profileImageUtils.d.ts +0 -39
- /package/esm/typings/src/book-2.0/{commitments/_misc → agent-source}/removeCommentsFromSystemMessage.d.ts +0 -0
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.
|
31
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.101.0-1';
|
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) {
|
@@ -3065,7 +3076,7 @@ const LLM_PROVIDER_PROFILES = {
|
|
3065
3076
|
};
|
3066
3077
|
/**
|
3067
3078
|
* TODO: Refactor this - each profile must be alongside the provider definition
|
3068
|
-
* TODO: [🕛] Unite `
|
3079
|
+
* TODO: [🕛] Unite `AgentBasicInformation`, `ChatParticipant`, `LlmExecutionTools` + `LlmToolsMetadata`
|
3069
3080
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
3070
3081
|
*/
|
3071
3082
|
|
@@ -3497,6 +3508,7 @@ function countCharacters(text) {
|
|
3497
3508
|
}
|
3498
3509
|
/**
|
3499
3510
|
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
3511
|
+
* TODO: [🧠][✌️] Make some Promptbook-native token system
|
3500
3512
|
*/
|
3501
3513
|
|
3502
3514
|
/**
|
@@ -3531,6 +3543,7 @@ function countLines(text) {
|
|
3531
3543
|
}
|
3532
3544
|
/**
|
3533
3545
|
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
3546
|
+
* TODO: [🧠][✌️] Make some Promptbook-native token system
|
3534
3547
|
*/
|
3535
3548
|
|
3536
3549
|
/**
|
@@ -3545,6 +3558,7 @@ function countPages(text) {
|
|
3545
3558
|
}
|
3546
3559
|
/**
|
3547
3560
|
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
3561
|
+
* TODO: [🧠][✌️] Make some Promptbook-native token system
|
3548
3562
|
*/
|
3549
3563
|
|
3550
3564
|
/**
|
@@ -3557,6 +3571,7 @@ function countParagraphs(text) {
|
|
3557
3571
|
}
|
3558
3572
|
/**
|
3559
3573
|
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
3574
|
+
* TODO: [🧠][✌️] Make some Promptbook-native token system
|
3560
3575
|
*/
|
3561
3576
|
|
3562
3577
|
/**
|
@@ -3577,6 +3592,7 @@ function countSentences(text) {
|
|
3577
3592
|
}
|
3578
3593
|
/**
|
3579
3594
|
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
3595
|
+
* TODO: [🧠][✌️] Make some Promptbook-native token system
|
3580
3596
|
*/
|
3581
3597
|
|
3582
3598
|
const defaultDiacriticsRemovalMap = [
|
@@ -3826,6 +3842,8 @@ for (let i = 0; i < defaultDiacriticsRemovalMap.length; i++) {
|
|
3826
3842
|
/**
|
3827
3843
|
* Removes diacritic marks (accents) from characters in a string.
|
3828
3844
|
*
|
3845
|
+
* Note: [🔂] This function is idempotent.
|
3846
|
+
*
|
3829
3847
|
* @param input The string containing diacritics to be normalized.
|
3830
3848
|
* @returns The string with diacritics removed or normalized.
|
3831
3849
|
* @public exported from `@promptbook/utils`
|
@@ -3854,6 +3872,8 @@ function countWords(text) {
|
|
3854
3872
|
}
|
3855
3873
|
/**
|
3856
3874
|
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
3875
|
+
* TODO: [🧠][✌️] Make some Promptbook-native token system
|
3876
|
+
* TODO: [✌️] `countWords` should be just `splitWords(...).length`, and all other counters should use this pattern as well
|
3857
3877
|
*/
|
3858
3878
|
|
3859
3879
|
/**
|
@@ -5353,6 +5373,8 @@ function $getGlobalScope() {
|
|
5353
5373
|
/**
|
5354
5374
|
* Normalizes a text string to SCREAMING_CASE (all uppercase with underscores).
|
5355
5375
|
*
|
5376
|
+
* Note: [🔂] This function is idempotent.
|
5377
|
+
*
|
5356
5378
|
* @param text The text string to be converted to SCREAMING_CASE format.
|
5357
5379
|
* @returns The normalized text in SCREAMING_CASE format.
|
5358
5380
|
* @example 'HELLO_WORLD'
|
@@ -5408,6 +5430,8 @@ function normalizeTo_SCREAMING_CASE(text) {
|
|
5408
5430
|
/**
|
5409
5431
|
* Normalizes a text string to snake_case format.
|
5410
5432
|
*
|
5433
|
+
* Note: [🔂] This function is idempotent.
|
5434
|
+
*
|
5411
5435
|
* @param text The text string to be converted to snake_case format.
|
5412
5436
|
* @returns The normalized text in snake_case format.
|
5413
5437
|
* @example 'hello_world'
|
@@ -5718,6 +5742,8 @@ function mimeTypeToExtension(value) {
|
|
5718
5742
|
/**
|
5719
5743
|
* Removes emojis from a string and fix whitespaces
|
5720
5744
|
*
|
5745
|
+
* Note: [🔂] This function is idempotent.
|
5746
|
+
*
|
5721
5747
|
* @param text with emojis
|
5722
5748
|
* @returns text without emojis
|
5723
5749
|
* @public exported from `@promptbook/utils`
|
@@ -6807,6 +6833,7 @@ const EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRA
|
|
6807
6833
|
/**
|
6808
6834
|
* Function parseNumber will parse number from string
|
6809
6835
|
*
|
6836
|
+
* Note: [🔂] This function is idempotent.
|
6810
6837
|
* Unlike Number.parseInt, Number.parseFloat it will never ever result in NaN
|
6811
6838
|
* Note: it also works only with decimal numbers
|
6812
6839
|
*
|
@@ -7069,6 +7096,7 @@ function normalizeTo_camelCase(text, _isFirstLetterCapital = false) {
|
|
7069
7096
|
/**
|
7070
7097
|
* Removes quotes from a string
|
7071
7098
|
*
|
7099
|
+
* Note: [🔂] This function is idempotent.
|
7072
7100
|
* Tip: This is very useful for post-processing of the result of the LLM model
|
7073
7101
|
* Note: This function removes only the same quotes from the beginning and the end of the string
|
7074
7102
|
* Note: There are two similar functions:
|
@@ -10691,7 +10719,9 @@ new Function(`
|
|
10691
10719
|
*/
|
10692
10720
|
|
10693
10721
|
/**
|
10694
|
-
* Makes first letter of a string
|
10722
|
+
* Makes first letter of a string lowercase
|
10723
|
+
*
|
10724
|
+
* Note: [🔂] This function is idempotent.
|
10695
10725
|
*
|
10696
10726
|
* @public exported from `@promptbook/utils`
|
10697
10727
|
*/
|
@@ -10761,6 +10791,8 @@ function normalizeTo_PascalCase(text) {
|
|
10761
10791
|
/**
|
10762
10792
|
* Take every whitespace (space, new line, tab) and replace it with a single space
|
10763
10793
|
*
|
10794
|
+
* Note: [🔂] This function is idempotent.
|
10795
|
+
*
|
10764
10796
|
* @public exported from `@promptbook/utils`
|
10765
10797
|
*/
|
10766
10798
|
function normalizeWhitespaces(sentence) {
|
@@ -10804,6 +10836,7 @@ function isSerializableAsJson(value) {
|
|
10804
10836
|
/**
|
10805
10837
|
* Function trimCodeBlock will trim starting and ending code block from the string if it is present.
|
10806
10838
|
*
|
10839
|
+
* Note: [🔂] This function is idempotent.
|
10807
10840
|
* Note: This is useful for post-processing of the result of the chat LLM model
|
10808
10841
|
* when the model wraps the result in the (markdown) code block.
|
10809
10842
|
*
|