@promptbook/cli 0.59.0-21 → 0.59.0-24

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 (48) hide show
  1. package/bin/promptbook-cli.js +2 -4
  2. package/esm/index.es.js +214 -211
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/cli.index.d.ts +4 -4
  5. package/esm/typings/src/_packages/core.index.d.ts +6 -6
  6. package/esm/typings/src/_packages/node.index.d.ts +2 -2
  7. package/esm/typings/src/_packages/types.index.d.ts +2 -1
  8. package/esm/typings/src/cli/actions/hello.d.ts +7 -0
  9. package/esm/typings/src/cli/actions/make.d.ts +7 -0
  10. package/esm/typings/src/cli/actions/prettify.d.ts +7 -0
  11. package/esm/typings/src/{conversion/prettify/prettifyPromptbookStringCli.d.ts → cli/promptbookCli.d.ts} +2 -2
  12. package/esm/typings/src/library/SimplePromptbookLibrary.d.ts +3 -1
  13. package/{umd/typings/src/library/constructors/createPromptbookLibraryFromDirectory.d.ts → esm/typings/src/library/constructors/createLibraryFromDirectory.d.ts} +2 -2
  14. package/esm/typings/src/library/constructors/createLibraryFromJson.d.ts +12 -0
  15. package/{umd/typings/src/library/constructors/createPromptbookLibraryFromPromise.d.ts → esm/typings/src/library/constructors/createLibraryFromPromise.d.ts} +3 -7
  16. package/{umd/typings/src/library/constructors/createPromptbookLibraryFromUrl.d.ts → esm/typings/src/library/constructors/createLibraryFromUrl.d.ts} +2 -2
  17. package/esm/typings/src/library/constructors/{createPromptbookSublibrary.d.ts → createSublibrary.d.ts} +1 -1
  18. package/esm/typings/src/library/libraryToJson.d.ts +8 -0
  19. package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -1
  20. package/package.json +2 -2
  21. package/umd/index.umd.js +170 -167
  22. package/umd/index.umd.js.map +1 -1
  23. package/umd/typings/src/_packages/cli.index.d.ts +4 -4
  24. package/umd/typings/src/_packages/core.index.d.ts +6 -6
  25. package/umd/typings/src/_packages/node.index.d.ts +2 -2
  26. package/umd/typings/src/_packages/types.index.d.ts +2 -1
  27. package/umd/typings/src/cli/actions/hello.d.ts +7 -0
  28. package/umd/typings/src/cli/actions/make.d.ts +7 -0
  29. package/umd/typings/src/cli/actions/prettify.d.ts +7 -0
  30. package/umd/typings/src/{conversion/prettify/prettifyPromptbookStringCli.d.ts → cli/promptbookCli.d.ts} +2 -2
  31. package/umd/typings/src/library/SimplePromptbookLibrary.d.ts +3 -1
  32. package/{esm/typings/src/library/constructors/createPromptbookLibraryFromDirectory.d.ts → umd/typings/src/library/constructors/createLibraryFromDirectory.d.ts} +2 -2
  33. package/umd/typings/src/library/constructors/createLibraryFromJson.d.ts +12 -0
  34. package/{esm/typings/src/library/constructors/createPromptbookLibraryFromPromise.d.ts → umd/typings/src/library/constructors/createLibraryFromPromise.d.ts} +3 -7
  35. package/umd/typings/src/library/constructors/createLibraryFromPromise.test.d.ts +1 -0
  36. package/{esm/typings/src/library/constructors/createPromptbookLibraryFromUrl.d.ts → umd/typings/src/library/constructors/createLibraryFromUrl.d.ts} +2 -2
  37. package/umd/typings/src/library/constructors/{createPromptbookSublibrary.d.ts → createSublibrary.d.ts} +1 -1
  38. package/umd/typings/src/library/libraryToJson.d.ts +8 -0
  39. package/umd/typings/src/library/libraryToJson.test.d.ts +1 -0
  40. package/umd/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -1
  41. package/esm/typings/src/library/constructors/createPromptbookLibraryFromSources.d.ts +0 -16
  42. package/umd/typings/src/library/constructors/createPromptbookLibraryFromSources.d.ts +0 -16
  43. /package/esm/typings/src/library/constructors/{createPromptbookLibraryFromDirectory.test.d.ts → createLibraryFromDirectory.test.d.ts} +0 -0
  44. /package/esm/typings/src/library/constructors/{createPromptbookLibraryFromPromise.test.d.ts → createLibraryFromJson.test.d.ts} +0 -0
  45. /package/esm/typings/src/library/constructors/{createPromptbookLibraryFromSources.test.d.ts → createLibraryFromPromise.test.d.ts} +0 -0
  46. /package/{umd/typings/src/library/constructors/createPromptbookLibraryFromDirectory.test.d.ts → esm/typings/src/library/libraryToJson.test.d.ts} +0 -0
  47. /package/umd/typings/src/library/constructors/{createPromptbookLibraryFromPromise.test.d.ts → createLibraryFromDirectory.test.d.ts} +0 -0
  48. /package/umd/typings/src/library/constructors/{createPromptbookLibraryFromSources.test.d.ts → createLibraryFromJson.test.d.ts} +0 -0
@@ -1,7 +1,7 @@
1
1
  import type { string_folder_path } from '../../types/typeAliases';
2
2
  import type { PromptbookLibrary } from '../PromptbookLibrary';
3
3
  /**
4
- * Options for `createPromptbookLibraryFromDirectory` function
4
+ * Options for `createLibraryFromDirectory` function
5
5
  */
6
6
  type CreatePromptbookLibraryFromDirectoryOptions = {
7
7
  /**
@@ -39,7 +39,7 @@ type CreatePromptbookLibraryFromDirectoryOptions = {
39
39
  * @param options - Misc options for the library
40
40
  * @returns PromptbookLibrary
41
41
  */
42
- export declare function createPromptbookLibraryFromDirectory(path: string_folder_path, options?: CreatePromptbookLibraryFromDirectoryOptions): Promise<PromptbookLibrary>;
42
+ export declare function createLibraryFromDirectory(path: string_folder_path, options?: CreatePromptbookLibraryFromDirectoryOptions): Promise<PromptbookLibrary>;
43
43
  export {};
44
44
  /**
45
45
  * TODO: !!!! [🧠] Library precompilation and do not mix markdown and json promptbooks
@@ -0,0 +1,12 @@
1
+ import type { PromptbookJson } from '../../types/PromptbookJson/PromptbookJson';
2
+ import { SimplePromptbookLibrary } from '../SimplePromptbookLibrary';
3
+ /**
4
+ * Creates PromptbookLibrary from array of PromptbookJson or PromptbookString
5
+ *
6
+ * Note: Functions `libraryToJson` and `createLibraryFromJson` are complementary
7
+ * Note: During the construction syntax and logic of all sources are validated
8
+ *
9
+ * @param promptbookSources
10
+ * @returns PromptbookLibrary
11
+ */
12
+ export declare function createLibraryFromJson(...promptbooks: Array<PromptbookJson>): Promise<SimplePromptbookLibrary>;
@@ -1,5 +1,4 @@
1
1
  import type { PromptbookJson } from '../../types/PromptbookJson/PromptbookJson';
2
- import type { PromptbookString } from '../../types/PromptbookString';
3
2
  import type { PromptbookLibrary } from '../PromptbookLibrary';
4
3
  /**
5
4
  * Constructs Promptbook from async sources
@@ -8,19 +7,16 @@ import type { PromptbookLibrary } from '../PromptbookLibrary';
8
7
  * - Factory function that returns Promise of array of PromptbookJson or PromptbookString
9
8
  *
10
9
  * Note: This is useful as internal tool for other constructor functions like
11
- * `createPromptbookLibraryFromUrl` or `createPromptbookLibraryFromDirectory`
10
+ * `createLibraryFromUrl` or `createLibraryFromDirectory`
12
11
  * Consider using those functions instead of this one
13
12
  *
14
13
  * Note: The function does NOT return promise it returns the library directly which waits for the sources to be resolved
15
14
  * when error occurs in given promise or factory function, it is thrown during `listPromptbooks` or `getPromptbookByUrl` call
16
15
  *
17
- * Note: Consider using `createPromptbookLibraryFromDirectory` or `createPromptbookLibraryFromUrl`
16
+ * Note: Consider using `createLibraryFromDirectory` or `createLibraryFromUrl`
18
17
  *
19
18
  * @param promptbookSourcesPromiseOrFactory
20
19
  * @returns PromptbookLibrary
21
20
  * @deprecated Do not use, it will became internal tool for other constructor functions
22
21
  */
23
- export declare function createPromptbookLibraryFromPromise(promptbookSourcesPromiseOrFactory: Promise<Array<PromptbookJson | PromptbookString>> | (() => Promise<Array<PromptbookJson | PromptbookString>>)): PromptbookLibrary;
24
- /**
25
- * TODO: !!!! [🧠] Library precompilation and do not mix markdown and json promptbooks
26
- */
22
+ export declare function createLibraryFromPromise(promptbookSourcesPromiseOrFactory: Promise<Array<PromptbookJson>> | (() => Promise<Array<PromptbookJson>>)): PromptbookLibrary;
@@ -1,7 +1,7 @@
1
1
  import type { string_url } from '../../types/typeAliases';
2
2
  import type { PromptbookLibrary } from '../PromptbookLibrary';
3
3
  /**
4
- * Options for `createPromptbookLibraryFromDirectory` function
4
+ * Options for `createLibraryFromDirectory` function
5
5
  */
6
6
  type CreatePromptbookLibraryFromUrlyOptions = {
7
7
  /**
@@ -22,7 +22,7 @@ type CreatePromptbookLibraryFromUrlyOptions = {
22
22
 
23
23
  * @returns PromptbookLibrary
24
24
  */
25
- export declare function createPromptbookLibraryFromUrl(url: string_url | URL, options: CreatePromptbookLibraryFromUrlyOptions): Promise<PromptbookLibrary>;
25
+ export declare function createLibraryFromUrl(url: string_url | URL, options: CreatePromptbookLibraryFromUrlyOptions): Promise<PromptbookLibrary>;
26
26
  export {};
27
27
  /**
28
28
  * TODO: !!!! [🧠] Library precompilation and do not mix markdown and json promptbooks
@@ -9,4 +9,4 @@ import type { PromptbookLibrary } from '../PromptbookLibrary';
9
9
  * @param promptbookSources
10
10
  * @returns PromptbookLibrary
11
11
  */
12
- export declare function createPromptbookSublibrary(library: PromptbookLibrary, predicate: (url: string_promptbook_url) => boolean): PromptbookLibrary;
12
+ export declare function createSublibrary(library: PromptbookLibrary, predicate: (url: string_promptbook_url) => boolean): PromptbookLibrary;
@@ -0,0 +1,8 @@
1
+ import type { PromptbookJson } from '../types/PromptbookJson/PromptbookJson';
2
+ import type { PromptbookLibrary } from './PromptbookLibrary';
3
+ /**
4
+ * Converts PromptbookLibrary to serialized JSON
5
+ *
6
+ * Note: Functions `libraryToJson` and `createLibraryFromJson` are complementary
7
+ */
8
+ export declare function libraryToJson(library: PromptbookLibrary): Promise<Array<PromptbookJson>>;
@@ -10,7 +10,7 @@ import type { RemoteServerOptions } from './interfaces/RemoteServerOptions';
10
10
  */
11
11
  export declare function startRemoteServer(options: RemoteServerOptions): IDestroyable;
12
12
  /**
13
- * TODO: [⚖] Expose the library to be able to connect to same library via createPromptbookLibraryFromUrl
13
+ * TODO: [⚖] Expose the library to be able to connect to same library via createLibraryFromUrl
14
14
  * TODO: Handle progress - support streaming
15
15
  * TODO: [🤹‍♂️] Do not hang up immediately but wait until client closes OR timeout
16
16
  * TODO: [🤹‍♂️] Timeout on chat to free up resources
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/cli",
3
- "version": "0.59.0-21",
3
+ "version": "0.59.0-24",
4
4
  "description": "Library to supercharge your use of large language models",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -52,7 +52,7 @@
52
52
  }
53
53
  ],
54
54
  "peerDependencies": {
55
- "@promptbook/core": "0.59.0-21"
55
+ "@promptbook/core": "0.59.0-24"
56
56
  },
57
57
  "main": "./umd/index.umd.js",
58
58
  "module": "./esm/index.es.js",
package/umd/index.umd.js CHANGED
@@ -1,15 +1,15 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('commander'), require('fs/promises'), require('glob-promise'), require('spacetrim'), require('waitasecond'), require('prettier'), require('prettier/parser-html')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'colors', 'commander', 'fs/promises', 'glob-promise', 'spacetrim', 'waitasecond', 'prettier', 'prettier/parser-html'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-cli"] = {}, global.colors, global.commander, global.promises, global.glob, global.spaceTrim, global.waitasecond, global.prettier, global.parserHtml));
5
- })(this, (function (exports, colors, commander, promises, glob, spaceTrim, waitasecond, prettier, parserHtml) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('commander'), require('spacetrim'), require('colors'), require('waitasecond'), require('fs/promises'), require('glob-promise'), require('prettier'), require('prettier/parser-html')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'commander', 'spacetrim', 'colors', 'waitasecond', 'fs/promises', 'glob-promise', 'prettier', 'prettier/parser-html'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-cli"] = {}, global.commander, global.spaceTrim, global.colors, global.waitasecond, global.promises, global.glob, global.prettier, global.parserHtml));
5
+ })(this, (function (exports, commander, spaceTrim, colors, waitasecond, promises, glob, prettier, parserHtml) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
9
- var colors__default = /*#__PURE__*/_interopDefaultLegacy(colors);
10
9
  var commander__default = /*#__PURE__*/_interopDefaultLegacy(commander);
11
- var glob__default = /*#__PURE__*/_interopDefaultLegacy(glob);
12
10
  var spaceTrim__default = /*#__PURE__*/_interopDefaultLegacy(spaceTrim);
11
+ var colors__default = /*#__PURE__*/_interopDefaultLegacy(colors);
12
+ var glob__default = /*#__PURE__*/_interopDefaultLegacy(glob);
13
13
  var parserHtml__default = /*#__PURE__*/_interopDefaultLegacy(parserHtml);
14
14
 
15
15
  /*! *****************************************************************************
@@ -147,7 +147,64 @@
147
147
  /**
148
148
  * The version of the Promptbook library
149
149
  */
150
- var PROMPTBOOK_VERSION = '0.59.0-20';
150
+ var PROMPTBOOK_VERSION = '0.59.0-23';
151
+
152
+ /**
153
+ * Initializes testing `hello` command for Promptbook CLI utilities
154
+ *
155
+ * @private part of `promptbookCli`
156
+ */
157
+ function initializeHello(program) {
158
+ var _this = this;
159
+ var helloCommand = program.command('hello');
160
+ helloCommand.description(spaceTrim__default["default"]("\n Just command for testing\n "));
161
+ helloCommand.argument('<name>', 'Your name');
162
+ helloCommand.option('-g, --greeting <greeting>', "Greeting", 'Hello');
163
+ helloCommand.action(function (name, _a) {
164
+ var greeting = _a.greeting;
165
+ return __awaiter(_this, void 0, void 0, function () {
166
+ return __generator(this, function (_b) {
167
+ switch (_b.label) {
168
+ case 0:
169
+ console.info(colors__default["default"].cyan("".concat(greeting, " ").concat(name)));
170
+ return [4 /*yield*/, waitasecond.forTime(1000)];
171
+ case 1:
172
+ _b.sent();
173
+ console.info(colors__default["default"].rainbow("Nice to meet you!"));
174
+ process.exit(0);
175
+ return [2 /*return*/];
176
+ }
177
+ });
178
+ });
179
+ });
180
+ }
181
+
182
+ /**
183
+ * Initializes `make` command for Promptbook CLI utilities
184
+ *
185
+ * @private part of `promptbookCli`
186
+ */
187
+ function initializeMake(program) {
188
+ var _this = this;
189
+ var helloCommand = program.command('make <path>');
190
+ helloCommand.description(spaceTrim__default["default"]("\n Makes a new promptbook library in given folder\n "));
191
+ helloCommand.argument('<path>', 'Path to promptbook folder');
192
+ helloCommand.option('-f, --format <format>', "Output format of builded library \"js\", \"ts\" or \"json\"", 'js');
193
+ helloCommand.option('-v, --validate', "Validate logic of promptbook", true);
194
+ // TODO: !!! Auto-detect AI api keys + explicit api keys as argv
195
+ helloCommand.action(function (path, _a) {
196
+ var format = _a.format, validate = _a.validate;
197
+ return __awaiter(_this, void 0, void 0, function () {
198
+ return __generator(this, function (_b) {
199
+ console.info({ path: path, format: format, validate: validate });
200
+ // TODO: !!! Implement
201
+ // TODO: !!! Validate logic
202
+ process.exit(0);
203
+ return [2 /*return*/];
204
+ });
205
+ });
206
+ });
207
+ }
151
208
 
152
209
  /**
153
210
  * Removes HTML or Markdown comments from a string.
@@ -226,7 +283,7 @@
226
283
  return PromptbookSyntaxError;
227
284
  }(Error));
228
285
 
229
- var promptbookLibrary = [{title:"Prepare Knowledge from Markdown",promptbookUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.59.0-20",parameters:[{name:"content",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledge",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{name:"knowledge",title:"Knowledge",dependentParameterNames:["content"],executionType:"PROMPT_TEMPLATE",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {content}",resultingParameterName:"knowledge"}],knowledge:[]}];
286
+ var promptbookLibrary = [{title:"Prepare Knowledge from Markdown",promptbookUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.59.0-23",parameters:[{name:"content",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledge",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{name:"knowledge",title:"Knowledge",dependentParameterNames:["content"],executionType:"PROMPT_TEMPLATE",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {content}",resultingParameterName:"knowledge"}],knowledge:[]}];
230
287
 
231
288
  /**
232
289
  * This error indicates errors during the execution of the promptbook
@@ -1847,6 +1904,7 @@
1847
1904
  * Library of promptbooks that groups together promptbooks for an application.
1848
1905
  * This implementation is a very thin wrapper around the Array / Map of promptbooks.
1849
1906
  *
1907
+ * @private use `createLibraryFromJson` instead
1850
1908
  * @see https://github.com/webgptorg/promptbook#promptbook-library
1851
1909
  */
1852
1910
  var SimplePromptbookLibrary = /** @class */ (function () {
@@ -1855,8 +1913,9 @@
1855
1913
  *
1856
1914
  * @param promptbooks !!!
1857
1915
  *
1916
+ * @private Use instead `createLibraryFromJson`
1858
1917
  * Note: During the construction logic of all promptbooks are validated
1859
- * Note: It is not recommended to use this constructor directly, use `createPromptbookLibraryFromSources` *(or other variant)* instead
1918
+ * Note: It is not recommended to use this constructor directly, use `createLibraryFromJson` *(or other variant)* instead
1860
1919
  */
1861
1920
  function SimplePromptbookLibrary() {
1862
1921
  var e_1, _a;
@@ -1925,68 +1984,23 @@
1925
1984
  /**
1926
1985
  * Creates PromptbookLibrary from array of PromptbookJson or PromptbookString
1927
1986
  *
1928
- * Note: You can combine `PromptbookString` (`.ptbk.md`) with `PromptbookJson` BUT it is not recommended
1987
+ * Note: Functions `libraryToJson` and `createLibraryFromJson` are complementary
1929
1988
  * Note: During the construction syntax and logic of all sources are validated
1930
1989
  *
1931
1990
  * @param promptbookSources
1932
1991
  * @returns PromptbookLibrary
1933
1992
  */
1934
- function createPromptbookLibraryFromSources() {
1935
- var promptbookSources = [];
1993
+ function createLibraryFromJson() {
1994
+ var promptbooks = [];
1936
1995
  for (var _i = 0; _i < arguments.length; _i++) {
1937
- promptbookSources[_i] = arguments[_i];
1996
+ promptbooks[_i] = arguments[_i];
1938
1997
  }
1939
1998
  return __awaiter(this, void 0, void 0, function () {
1940
- var promptbooks, promptbookSources_1, promptbookSources_1_1, source, promptbook, e_1_1;
1941
- var e_1, _a;
1942
- return __generator(this, function (_b) {
1943
- switch (_b.label) {
1944
- case 0:
1945
- promptbooks = new Array();
1946
- _b.label = 1;
1947
- case 1:
1948
- _b.trys.push([1, 8, 9, 10]);
1949
- promptbookSources_1 = __values(promptbookSources), promptbookSources_1_1 = promptbookSources_1.next();
1950
- _b.label = 2;
1951
- case 2:
1952
- if (!!promptbookSources_1_1.done) return [3 /*break*/, 7];
1953
- source = promptbookSources_1_1.value;
1954
- promptbook = void 0;
1955
- if (!(typeof source === 'string')) return [3 /*break*/, 4];
1956
- return [4 /*yield*/, promptbookStringToJson(source)];
1957
- case 3:
1958
- // Note: When directly creating from string, no need to validate the source
1959
- // The validation is performed always before execution
1960
- promptbook = _b.sent();
1961
- return [3 /*break*/, 5];
1962
- case 4:
1963
- promptbook = source;
1964
- _b.label = 5;
1965
- case 5:
1966
- promptbooks.push(promptbook);
1967
- _b.label = 6;
1968
- case 6:
1969
- promptbookSources_1_1 = promptbookSources_1.next();
1970
- return [3 /*break*/, 2];
1971
- case 7: return [3 /*break*/, 10];
1972
- case 8:
1973
- e_1_1 = _b.sent();
1974
- e_1 = { error: e_1_1 };
1975
- return [3 /*break*/, 10];
1976
- case 9:
1977
- try {
1978
- if (promptbookSources_1_1 && !promptbookSources_1_1.done && (_a = promptbookSources_1.return)) _a.call(promptbookSources_1);
1979
- }
1980
- finally { if (e_1) throw e_1.error; }
1981
- return [7 /*endfinally*/];
1982
- case 10: return [2 /*return*/, new (SimplePromptbookLibrary.bind.apply(SimplePromptbookLibrary, __spreadArray([void 0], __read(promptbooks), false)))()];
1983
- }
1999
+ return __generator(this, function (_a) {
2000
+ return [2 /*return*/, new (SimplePromptbookLibrary.bind.apply(SimplePromptbookLibrary, __spreadArray([void 0], __read(promptbooks), false)))()];
1984
2001
  });
1985
2002
  });
1986
2003
  }
1987
- /**
1988
- * TODO: !!!! [🧠] Library precompilation and do not mix markdown and json promptbooks
1989
- */
1990
2004
 
1991
2005
  /* tslint:disable */
1992
2006
  function normalizeToKebabCase(sentence) {
@@ -2051,7 +2065,7 @@
2051
2065
  switch (_b.label) {
2052
2066
  case 0:
2053
2067
  content = options.content, llmTools = options.llmTools, _a = options.isVerbose, isVerbose = _a === void 0 ? false : _a;
2054
- return [4 /*yield*/, createPromptbookLibraryFromSources.apply(void 0, __spreadArray([], __read(promptbookLibrary), false))];
2068
+ return [4 /*yield*/, createLibraryFromJson.apply(void 0, __spreadArray([], __read(promptbookLibrary), false))];
2055
2069
  case 1:
2056
2070
  library = _b.sent();
2057
2071
  promptbook = library.getPromptbookByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md');
@@ -3369,117 +3383,106 @@
3369
3383
  */
3370
3384
 
3371
3385
  /**
3372
- * Runs CLI script for prettifying promptbooks
3386
+ * Initializes `prettify` command for Promptbook CLI utilities
3387
+ *
3388
+ * @private part of `promptbookCli`
3373
3389
  */
3374
- function prettifyPromptbookStringCli() {
3390
+ function initializePrettify(program) {
3391
+ var _this = this;
3392
+ var prettifyCommand = program.command('prettify');
3393
+ prettifyCommand.description(spaceTrim__default["default"]("\n Iterates over promptbooks and does multiple enhancing operations on them:\n\n 1) Adds Mermaid graph\n 2) Prettifies the markdown\n "));
3394
+ prettifyCommand.argument('<filesGlob>', 'Promptbooks to prettify as glob pattern');
3395
+ prettifyCommand.option('-i, --ignore <glob>', "Ignore as glob pattern");
3396
+ prettifyCommand.action(function (filesGlob, _a) {
3397
+ var ignore = _a.ignore;
3398
+ return __awaiter(_this, void 0, void 0, function () {
3399
+ var filePaths, filePaths_1, filePaths_1_1, filePath, promptbookMarkdown, error_1, e_1_1;
3400
+ var e_1, _b;
3401
+ return __generator(this, function (_c) {
3402
+ switch (_c.label) {
3403
+ case 0: return [4 /*yield*/, glob__default["default"](filesGlob, { ignore: ignore })];
3404
+ case 1:
3405
+ filePaths = _c.sent();
3406
+ _c.label = 2;
3407
+ case 2:
3408
+ _c.trys.push([2, 11, 12, 13]);
3409
+ filePaths_1 = __values(filePaths), filePaths_1_1 = filePaths_1.next();
3410
+ _c.label = 3;
3411
+ case 3:
3412
+ if (!!filePaths_1_1.done) return [3 /*break*/, 10];
3413
+ filePath = filePaths_1_1.value;
3414
+ if (!filePath.endsWith('.ptbk.md')) {
3415
+ console.warn(colors__default["default"].yellow("Skipping prettify of non-promptbook ".concat(filePath)));
3416
+ return [3 /*break*/, 9];
3417
+ }
3418
+ return [4 /*yield*/, promises.readFile(filePath, 'utf-8')];
3419
+ case 4:
3420
+ promptbookMarkdown = (_c.sent());
3421
+ _c.label = 5;
3422
+ case 5:
3423
+ _c.trys.push([5, 8, , 9]);
3424
+ return [4 /*yield*/, prettifyPromptbookString(promptbookMarkdown, {
3425
+ isGraphAdded: true,
3426
+ isPrettifyed: true,
3427
+ // <- [🕌]
3428
+ })];
3429
+ case 6:
3430
+ promptbookMarkdown = _c.sent();
3431
+ return [4 /*yield*/, promises.writeFile(filePath, promptbookMarkdown)];
3432
+ case 7:
3433
+ _c.sent();
3434
+ console.info(colors__default["default"].green("Prettify ".concat(filePath)));
3435
+ return [3 /*break*/, 9];
3436
+ case 8:
3437
+ error_1 = _c.sent();
3438
+ if (!(error_1 instanceof Error)) {
3439
+ throw error_1;
3440
+ }
3441
+ console.info(colors__default["default"].red("Prettify ".concat(error_1.name, " ").concat(filePath)));
3442
+ console.error(colors__default["default"].bgRed(error_1.name));
3443
+ console.error(error_1);
3444
+ process.exit(1);
3445
+ return [3 /*break*/, 9];
3446
+ case 9:
3447
+ filePaths_1_1 = filePaths_1.next();
3448
+ return [3 /*break*/, 3];
3449
+ case 10: return [3 /*break*/, 13];
3450
+ case 11:
3451
+ e_1_1 = _c.sent();
3452
+ e_1 = { error: e_1_1 };
3453
+ return [3 /*break*/, 13];
3454
+ case 12:
3455
+ try {
3456
+ if (filePaths_1_1 && !filePaths_1_1.done && (_b = filePaths_1.return)) _b.call(filePaths_1);
3457
+ }
3458
+ finally { if (e_1) throw e_1.error; }
3459
+ return [7 /*endfinally*/];
3460
+ case 13:
3461
+ process.exit(0);
3462
+ return [2 /*return*/];
3463
+ }
3464
+ });
3465
+ });
3466
+ });
3467
+ }
3468
+
3469
+ /**
3470
+ * Runs CLI utilities of Promptbook package
3471
+ */
3472
+ function promptbookCli() {
3375
3473
  return __awaiter(this, void 0, void 0, function () {
3376
- var program, prettifyCommand, helloCommand;
3377
- var _this = this;
3474
+ var program;
3378
3475
  return __generator(this, function (_a) {
3379
3476
  if (!isRunningInNode()) {
3380
- throw new Error(spaceTrim.spaceTrim("\n Function prettifyPromptbookStringCli is initiator of CLI script and should be run in Node.js environment.\n\n - In browser use prettifyPromptbookString.\n\n "));
3477
+ throw new Error(spaceTrim.spaceTrim("\n Function promptbookCli is initiator of CLI script and should be run in Node.js environment.\n\n - In browser use function exported from `@promptbook/utils` or `@promptbook/core` directly, for example `prettifyPromptbookString`.\n\n "));
3381
3478
  }
3382
3479
  program = new commander__default["default"].Command();
3383
3480
  program.name('promptbook');
3384
3481
  program.version(PROMPTBOOK_VERSION);
3385
- program.description(spaceTrim.spaceTrim("\n Promptbook utilities\n "));
3386
- prettifyCommand = program.command('prettify');
3387
- prettifyCommand.description(spaceTrim.spaceTrim("\n Iterates over promptbooks and does multiple enhancing operations on them:\n 1) Adds Mermaid graph\n 2) Prettifies the markdown\n "));
3388
- prettifyCommand.argument('<filesGlob>', 'Promptbooks to prettify as glob pattern');
3389
- prettifyCommand.option('-i, --ignore <glob>', "Ignore as glob pattern");
3390
- prettifyCommand.action(function (filesGlob, _a) {
3391
- var ignore = _a.ignore;
3392
- return __awaiter(_this, void 0, void 0, function () {
3393
- var filePaths, filePaths_1, filePaths_1_1, filePath, promptbookMarkdown, error_1, e_1_1;
3394
- var e_1, _b;
3395
- return __generator(this, function (_c) {
3396
- switch (_c.label) {
3397
- case 0: return [4 /*yield*/, glob__default["default"](filesGlob, { ignore: ignore })];
3398
- case 1:
3399
- filePaths = _c.sent();
3400
- _c.label = 2;
3401
- case 2:
3402
- _c.trys.push([2, 11, 12, 13]);
3403
- filePaths_1 = __values(filePaths), filePaths_1_1 = filePaths_1.next();
3404
- _c.label = 3;
3405
- case 3:
3406
- if (!!filePaths_1_1.done) return [3 /*break*/, 10];
3407
- filePath = filePaths_1_1.value;
3408
- if (!filePath.endsWith('.ptbk.md')) {
3409
- console.warn(colors__default["default"].yellow("Skipping prettify of non-promptbook ".concat(filePath)));
3410
- return [3 /*break*/, 9];
3411
- }
3412
- return [4 /*yield*/, promises.readFile(filePath, 'utf-8')];
3413
- case 4:
3414
- promptbookMarkdown = (_c.sent());
3415
- _c.label = 5;
3416
- case 5:
3417
- _c.trys.push([5, 8, , 9]);
3418
- return [4 /*yield*/, prettifyPromptbookString(promptbookMarkdown, {
3419
- isGraphAdded: true,
3420
- isPrettifyed: true,
3421
- // <- [🕌]
3422
- })];
3423
- case 6:
3424
- promptbookMarkdown = _c.sent();
3425
- return [4 /*yield*/, promises.writeFile(filePath, promptbookMarkdown)];
3426
- case 7:
3427
- _c.sent();
3428
- console.info(colors__default["default"].green("Prettify ".concat(filePath)));
3429
- return [3 /*break*/, 9];
3430
- case 8:
3431
- error_1 = _c.sent();
3432
- if (!(error_1 instanceof Error)) {
3433
- throw error_1;
3434
- }
3435
- console.info(colors__default["default"].red("Prettify ".concat(error_1.name, " ").concat(filePath)));
3436
- console.error(colors__default["default"].bgRed(error_1.name));
3437
- console.error(error_1);
3438
- process.exit(1);
3439
- return [3 /*break*/, 9];
3440
- case 9:
3441
- filePaths_1_1 = filePaths_1.next();
3442
- return [3 /*break*/, 3];
3443
- case 10: return [3 /*break*/, 13];
3444
- case 11:
3445
- e_1_1 = _c.sent();
3446
- e_1 = { error: e_1_1 };
3447
- return [3 /*break*/, 13];
3448
- case 12:
3449
- try {
3450
- if (filePaths_1_1 && !filePaths_1_1.done && (_b = filePaths_1.return)) _b.call(filePaths_1);
3451
- }
3452
- finally { if (e_1) throw e_1.error; }
3453
- return [7 /*endfinally*/];
3454
- case 13:
3455
- process.exit(0);
3456
- return [2 /*return*/];
3457
- }
3458
- });
3459
- });
3460
- });
3461
- helloCommand = program.command('hello');
3462
- helloCommand.description(spaceTrim.spaceTrim("\n Just command for testing\n "));
3463
- helloCommand.argument('<name>', 'Your name');
3464
- helloCommand.option('-g, --greeting <greeting>', "Greeting", 'Hello');
3465
- helloCommand.action(function (name, _a) {
3466
- var greeting = _a.greeting;
3467
- return __awaiter(_this, void 0, void 0, function () {
3468
- return __generator(this, function (_b) {
3469
- switch (_b.label) {
3470
- case 0:
3471
- console.info(colors__default["default"].cyan("".concat(greeting, " ").concat(name)));
3472
- return [4 /*yield*/, waitasecond.forTime(1000)];
3473
- case 1:
3474
- _b.sent();
3475
- console.info(colors__default["default"].rainbow("Nice to meet you!"));
3476
- process.exit(0);
3477
- return [2 /*return*/];
3478
- }
3479
- });
3480
- });
3481
- });
3482
- //------
3482
+ program.description(spaceTrim.spaceTrim("\n Promptbook utilities for enhancing workflow with promptbooks\n "));
3483
+ initializeHello(program);
3484
+ initializeMake(program);
3485
+ initializePrettify(program);
3483
3486
  program.parse(process.argv);
3484
3487
  return [2 /*return*/];
3485
3488
  });
@@ -3495,13 +3498,13 @@
3495
3498
  /**
3496
3499
  * Hidden utilities which should not be used by external consumers.
3497
3500
  */
3498
- var __ = {
3501
+ var __CLI = {
3499
3502
  // Note: [🥠]
3500
- prettifyPromptbookStringCli: prettifyPromptbookStringCli,
3503
+ __initialize: promptbookCli,
3501
3504
  };
3502
3505
 
3503
3506
  exports.PROMPTBOOK_VERSION = PROMPTBOOK_VERSION;
3504
- exports.__ = __;
3507
+ exports.__CLI = __CLI;
3505
3508
 
3506
3509
  Object.defineProperty(exports, '__esModule', { value: true });
3507
3510