@promptbook/remote-server 0.101.0-0 → 0.101.0-10

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 (61) hide show
  1. package/README.md +45 -0
  2. package/esm/index.es.js +31 -6
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/components.index.d.ts +18 -0
  5. package/esm/typings/src/_packages/core.index.d.ts +2 -0
  6. package/esm/typings/src/_packages/types.index.d.ts +6 -0
  7. package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +41 -3
  8. package/esm/typings/src/book-2.0/agent-source/parseParameters.d.ts +13 -0
  9. package/esm/typings/src/book-2.0/commitments/ACTION/ACTION.d.ts +8 -2
  10. package/esm/typings/src/book-2.0/commitments/DELETE/DELETE.d.ts +59 -0
  11. package/esm/typings/src/book-2.0/commitments/FORMAT/FORMAT.d.ts +8 -2
  12. package/esm/typings/src/book-2.0/commitments/GOAL/GOAL.d.ts +45 -0
  13. package/esm/typings/src/book-2.0/commitments/KNOWLEDGE/KNOWLEDGE.d.ts +1 -1
  14. package/esm/typings/src/book-2.0/commitments/MEMORY/MEMORY.d.ts +46 -0
  15. package/esm/typings/src/book-2.0/commitments/MESSAGE/MESSAGE.d.ts +47 -0
  16. package/esm/typings/src/book-2.0/commitments/META/META.d.ts +62 -0
  17. package/esm/typings/src/book-2.0/commitments/MODEL/MODEL.d.ts +8 -2
  18. package/esm/typings/src/book-2.0/commitments/NOTE/NOTE.d.ts +8 -2
  19. package/esm/typings/src/book-2.0/commitments/PERSONA/PERSONA.d.ts +8 -2
  20. package/esm/typings/src/book-2.0/commitments/SCENARIO/SCENARIO.d.ts +46 -0
  21. package/esm/typings/src/book-2.0/commitments/STYLE/STYLE.d.ts +8 -2
  22. package/esm/typings/src/book-2.0/commitments/index.d.ts +7 -3
  23. package/esm/typings/src/book-components/AvatarProfile/AvatarProfile/MockedChat.d.ts +46 -0
  24. package/esm/typings/src/book-components/AvatarProfile/AvatarProfile/index.d.ts +3 -0
  25. package/esm/typings/src/book-components/BookEditor/BookEditor.d.ts +10 -0
  26. package/esm/typings/src/book-components/BookEditor/BookEditorInner.d.ts +3 -0
  27. package/esm/typings/src/book-components/Chat/Chat/Chat.d.ts +0 -5
  28. package/esm/typings/src/book-components/Chat/Chat/ChatProps.d.ts +28 -2
  29. package/esm/typings/src/book-components/Chat/Chat/constants.d.ts +8 -0
  30. package/esm/typings/src/book-components/Chat/examples/ChatMarkdownDemo.d.ts +16 -0
  31. package/esm/typings/src/book-components/Chat/utils/renderMarkdown.d.ts +21 -0
  32. package/esm/typings/src/book-components/Chat/utils/renderMarkdown.test.d.ts +1 -0
  33. package/esm/typings/src/book-components/icons/ArrowIcon.d.ts +9 -0
  34. package/esm/typings/src/book-components/icons/ResetIcon.d.ts +6 -0
  35. package/esm/typings/src/book-components/icons/SendIcon.d.ts +8 -0
  36. package/esm/typings/src/book-components/icons/TemplateIcon.d.ts +8 -0
  37. package/esm/typings/src/utils/markdown/escapeMarkdownBlock.d.ts +2 -0
  38. package/esm/typings/src/utils/markdown/humanizeAiText.d.ts +2 -0
  39. package/esm/typings/src/utils/markdown/humanizeAiTextEllipsis.d.ts +1 -0
  40. package/esm/typings/src/utils/markdown/humanizeAiTextEmdashed.d.ts +1 -0
  41. package/esm/typings/src/utils/markdown/humanizeAiTextQuotes.d.ts +1 -0
  42. package/esm/typings/src/utils/markdown/humanizeAiTextWhitespace.d.ts +1 -0
  43. package/esm/typings/src/utils/markdown/prettifyMarkdown.d.ts +8 -0
  44. package/esm/typings/src/utils/markdown/promptbookifyAiText.d.ts +1 -0
  45. package/esm/typings/src/utils/normalization/capitalize.d.ts +2 -0
  46. package/esm/typings/src/utils/normalization/decapitalize.d.ts +3 -1
  47. package/esm/typings/src/utils/normalization/normalizeTo_SCREAMING_CASE.d.ts +2 -0
  48. package/esm/typings/src/utils/normalization/normalizeTo_snake_case.d.ts +2 -0
  49. package/esm/typings/src/utils/normalization/normalizeWhitespaces.d.ts +2 -0
  50. package/esm/typings/src/utils/normalization/removeDiacritics.d.ts +2 -0
  51. package/esm/typings/src/utils/parseNumber.d.ts +1 -0
  52. package/esm/typings/src/utils/removeEmojis.d.ts +2 -0
  53. package/esm/typings/src/utils/removeQuotes.d.ts +1 -0
  54. package/esm/typings/src/utils/serialization/deepClone.d.ts +1 -0
  55. package/esm/typings/src/utils/trimCodeBlock.d.ts +1 -0
  56. package/esm/typings/src/utils/validators/url/isValidUrl.d.ts +1 -0
  57. package/esm/typings/src/utils/validators/uuid/isValidUuid.d.ts +2 -0
  58. package/esm/typings/src/version.d.ts +1 -1
  59. package/package.json +2 -2
  60. package/umd/index.umd.js +36 -10
  61. package/umd/index.umd.js.map +1 -1
package/README.md CHANGED
@@ -49,6 +49,51 @@ npm install @promptbook/remote-server
49
49
  ```
50
50
 
51
51
 
52
+ Remote server implementation for Promptbook, enabling distributed execution of promptbook pipelines across network boundaries with REST API and WebSocket support.
53
+
54
+ ## 🎯 Purpose and Motivation
55
+
56
+ This package provides a remote server that allows promptbook pipelines to be executed over the network. It enables distributed architectures where promptbook execution can be centralized on powerful servers while clients can access the functionality remotely, making it ideal for scaling promptbook applications and providing API access to promptbook collections.
57
+
58
+ ## 🔧 High-Level Functionality
59
+
60
+ The package provides remote server capabilities:
61
+ - **HTTP REST API**: RESTful endpoints for pipeline execution and management
62
+ - **WebSocket Support**: Real-time communication for streaming execution results
63
+ - **Authentication**: Support for both anonymous and application-based authentication
64
+ - **Pipeline Management**: Remote access to promptbook collections and pipelines
65
+ - **Execution Orchestration**: Distributed execution of promptbook pipelines
66
+ - **OpenAI Compatibility**: OpenAI-compatible API endpoints for seamless integration
67
+
68
+ ## ✨ Key Features
69
+
70
+ - 🌐 **Remote Execution** - Execute promptbook pipelines over HTTP/WebSocket
71
+ - 🔐 **Authentication Modes** - Support for anonymous and application-based access
72
+ - 📡 **Real-time Communication** - WebSocket support for streaming results
73
+ - 🔌 **OpenAI Compatible** - Use promptbooks as OpenAI-compatible models
74
+ - 🚀 **Scalable Architecture** - Distribute promptbook execution across servers
75
+ - 📊 **Pipeline Management** - Remote access to collections and individual pipelines
76
+ - 🛡️ **Security** - Configurable authentication and access control
77
+ - ⚡ **High Performance** - Optimized for concurrent pipeline execution
78
+
79
+ ## 📦 Exported Entities
80
+
81
+ ### Version Information
82
+ - `BOOK_LANGUAGE_VERSION` - Current book language version
83
+ - `PROMPTBOOK_ENGINE_VERSION` - Current engine version
84
+
85
+ ### Server Management
86
+ - `startRemoteServer` - Start the remote promptbook server
87
+
88
+ ### Configuration Types
89
+ - `RemoteServerOptions` - Configuration options for remote server (type)
90
+
91
+ ### Authentication Types
92
+ - `Identification` - Base identification interface (type)
93
+ - `ApplicationModeIdentification` - Application mode identification (type)
94
+ - `AnonymousModeIdentification` - Anonymous mode identification (type)
95
+
96
+ > 💡 This package provides remote server functionality for promptbook applications. For the core functionality, see [@promptbook/core](#-packages) or install all packages with `npm i ptbk`
52
97
 
53
98
 
54
99
  ---
package/esm/index.es.js CHANGED
@@ -11,9 +11,6 @@ import { spawn } from 'child_process';
11
11
  import { stat, access, constants, readFile, writeFile, readdir, mkdir } from 'fs/promises';
12
12
  import { join, basename, dirname, isAbsolute } from 'path';
13
13
  import { Subject } from 'rxjs';
14
- import parserHtml from 'prettier/parser-html';
15
- import parserMarkdown from 'prettier/parser-markdown';
16
- import { format } from 'prettier/standalone';
17
14
  import hexEncoder from 'crypto-js/enc-hex';
18
15
  import sha256 from 'crypto-js/sha256';
19
16
  import { SHA256 } from 'crypto-js';
@@ -34,7 +31,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
34
31
  * @generated
35
32
  * @see https://github.com/webgptorg/promptbook
36
33
  */
37
- const PROMPTBOOK_ENGINE_VERSION = '0.101.0-0';
34
+ const PROMPTBOOK_ENGINE_VERSION = '0.101.0-10';
38
35
  /**
39
36
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
40
37
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -1299,6 +1296,7 @@ function checkSerializableAsJson(options) {
1299
1296
  /**
1300
1297
  * Creates a deep clone of the given object
1301
1298
  *
1299
+ * Note: [🔂] This function is idempotent.
1302
1300
  * Note: This method only works for objects that are fully serializable to JSON and do not contain functions, Dates, or special types.
1303
1301
  *
1304
1302
  * @param objectValue The object to clone.
@@ -1464,6 +1462,7 @@ function isValidPromptbookVersion(version) {
1464
1462
  /**
1465
1463
  * Tests if given string is valid URL.
1466
1464
  *
1465
+ * Note: [🔂] This function is idempotent.
1467
1466
  * Note: Dataurl are considered perfectly valid.
1468
1467
  * Note: There are two similar functions:
1469
1468
  * - `isValidUrl` which tests any URL
@@ -2372,8 +2371,18 @@ function validatePipelineString(pipelineString) {
2372
2371
  * @private withing the package because of HUGE size of prettier dependency
2373
2372
  */
2374
2373
  function prettifyMarkdown(content) {
2374
+ // In browser/Next.js environments, just return the original content
2375
+ // since prettier parsers are not available and would cause bundling issues
2376
+ if (typeof window !== 'undefined') {
2377
+ return content;
2378
+ }
2375
2379
  try {
2376
- return format(content, {
2380
+ // Use dynamic require to avoid static imports that cause bundling issues
2381
+ // This will only work in Node.js environments
2382
+ const prettierStandalone = eval('require')('prettier/standalone');
2383
+ const parserMarkdown = eval('require')('prettier/parser-markdown');
2384
+ const parserHtml = eval('require')('prettier/parser-html');
2385
+ return prettierStandalone.format(content, {
2377
2386
  parser: 'markdown',
2378
2387
  plugins: [parserMarkdown, parserHtml],
2379
2388
  // TODO: DRY - make some import or auto-copy of .prettierrc
@@ -2401,6 +2410,8 @@ function prettifyMarkdown(content) {
2401
2410
  /**
2402
2411
  * Makes first letter of a string uppercase
2403
2412
  *
2413
+ * Note: [🔂] This function is idempotent.
2414
+ *
2404
2415
  * @public exported from `@promptbook/utils`
2405
2416
  */
2406
2417
  function capitalize(word) {
@@ -3241,6 +3252,8 @@ function $getGlobalScope() {
3241
3252
  /**
3242
3253
  * Normalizes a text string to SCREAMING_CASE (all uppercase with underscores).
3243
3254
  *
3255
+ * Note: [🔂] This function is idempotent.
3256
+ *
3244
3257
  * @param text The text string to be converted to SCREAMING_CASE format.
3245
3258
  * @returns The normalized text in SCREAMING_CASE format.
3246
3259
  * @example 'HELLO_WORLD'
@@ -3296,6 +3309,8 @@ function normalizeTo_SCREAMING_CASE(text) {
3296
3309
  /**
3297
3310
  * Normalizes a text string to snake_case format.
3298
3311
  *
3312
+ * Note: [🔂] This function is idempotent.
3313
+ *
3299
3314
  * @param text The text string to be converted to snake_case format.
3300
3315
  * @returns The normalized text in snake_case format.
3301
3316
  * @example 'hello_world'
@@ -3713,6 +3728,8 @@ for (let i = 0; i < defaultDiacriticsRemovalMap.length; i++) {
3713
3728
  /**
3714
3729
  * Removes diacritic marks (accents) from characters in a string.
3715
3730
  *
3731
+ * Note: [🔂] This function is idempotent.
3732
+ *
3716
3733
  * @param input The string containing diacritics to be normalized.
3717
3734
  * @returns The string with diacritics removed or normalized.
3718
3735
  * @public exported from `@promptbook/utils`
@@ -3867,6 +3884,8 @@ function mimeTypeToExtension(value) {
3867
3884
  /**
3868
3885
  * Removes emojis from a string and fix whitespaces
3869
3886
  *
3887
+ * Note: [🔂] This function is idempotent.
3888
+ *
3870
3889
  * @param text with emojis
3871
3890
  * @returns text without emojis
3872
3891
  * @public exported from `@promptbook/utils`
@@ -7025,7 +7044,9 @@ new Function(`
7025
7044
  */
7026
7045
 
7027
7046
  /**
7028
- * Makes first letter of a string uppercase
7047
+ * Makes first letter of a string lowercase
7048
+ *
7049
+ * Note: [🔂] This function is idempotent.
7029
7050
  *
7030
7051
  * @public exported from `@promptbook/utils`
7031
7052
  */
@@ -7095,6 +7116,8 @@ function normalizeTo_PascalCase(text) {
7095
7116
  /**
7096
7117
  * Take every whitespace (space, new line, tab) and replace it with a single space
7097
7118
  *
7119
+ * Note: [🔂] This function is idempotent.
7120
+ *
7098
7121
  * @public exported from `@promptbook/utils`
7099
7122
  */
7100
7123
  function normalizeWhitespaces(sentence) {
@@ -7104,6 +7127,7 @@ function normalizeWhitespaces(sentence) {
7104
7127
  /**
7105
7128
  * Removes quotes from a string
7106
7129
  *
7130
+ * Note: [🔂] This function is idempotent.
7107
7131
  * Tip: This is very useful for post-processing of the result of the LLM model
7108
7132
  * Note: This function removes only the same quotes from the beginning and the end of the string
7109
7133
  * Note: There are two similar functions:
@@ -7127,6 +7151,7 @@ function removeQuotes(text) {
7127
7151
  /**
7128
7152
  * Function trimCodeBlock will trim starting and ending code block from the string if it is present.
7129
7153
  *
7154
+ * Note: [🔂] This function is idempotent.
7130
7155
  * Note: This is useful for post-processing of the result of the chat LLM model
7131
7156
  * when the model wraps the result in the (markdown) code block.
7132
7157
  *