@promptbook/cli 0.59.0-21 → 0.59.0-23
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/bin/promptbook-cli.js +1 -1
- package/esm/index.es.js +184 -209
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/cli.index.d.ts +2 -2
- package/esm/typings/src/_packages/core.index.d.ts +6 -6
- package/esm/typings/src/_packages/node.index.d.ts +2 -2
- package/esm/typings/src/_packages/types.index.d.ts +2 -1
- package/esm/typings/src/cli/actions/hello.d.ts +7 -0
- package/esm/typings/src/cli/actions/make.d.ts +7 -0
- package/esm/typings/src/cli/actions/prettify.d.ts +7 -0
- package/esm/typings/src/{conversion/prettify/prettifyPromptbookStringCli.d.ts → cli/promptbookCli.d.ts} +2 -2
- package/esm/typings/src/library/SimplePromptbookLibrary.d.ts +3 -1
- package/{umd/typings/src/library/constructors/createPromptbookLibraryFromDirectory.d.ts → esm/typings/src/library/constructors/createLibraryFromDirectory.d.ts} +2 -2
- package/esm/typings/src/library/constructors/createLibraryFromJson.d.ts +12 -0
- package/{umd/typings/src/library/constructors/createPromptbookLibraryFromPromise.d.ts → esm/typings/src/library/constructors/createLibraryFromPromise.d.ts} +3 -7
- package/{umd/typings/src/library/constructors/createPromptbookLibraryFromUrl.d.ts → esm/typings/src/library/constructors/createLibraryFromUrl.d.ts} +2 -2
- package/esm/typings/src/library/constructors/{createPromptbookSublibrary.d.ts → createSublibrary.d.ts} +1 -1
- package/esm/typings/src/library/libraryToJson.d.ts +8 -0
- package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +140 -165
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/src/_packages/cli.index.d.ts +2 -2
- package/umd/typings/src/_packages/core.index.d.ts +6 -6
- package/umd/typings/src/_packages/node.index.d.ts +2 -2
- package/umd/typings/src/_packages/types.index.d.ts +2 -1
- package/umd/typings/src/cli/actions/hello.d.ts +7 -0
- package/umd/typings/src/cli/actions/make.d.ts +7 -0
- package/umd/typings/src/cli/actions/prettify.d.ts +7 -0
- package/umd/typings/src/{conversion/prettify/prettifyPromptbookStringCli.d.ts → cli/promptbookCli.d.ts} +2 -2
- package/umd/typings/src/library/SimplePromptbookLibrary.d.ts +3 -1
- package/{esm/typings/src/library/constructors/createPromptbookLibraryFromDirectory.d.ts → umd/typings/src/library/constructors/createLibraryFromDirectory.d.ts} +2 -2
- package/umd/typings/src/library/constructors/createLibraryFromJson.d.ts +12 -0
- package/{esm/typings/src/library/constructors/createPromptbookLibraryFromPromise.d.ts → umd/typings/src/library/constructors/createLibraryFromPromise.d.ts} +3 -7
- package/umd/typings/src/library/constructors/createLibraryFromPromise.test.d.ts +1 -0
- package/{esm/typings/src/library/constructors/createPromptbookLibraryFromUrl.d.ts → umd/typings/src/library/constructors/createLibraryFromUrl.d.ts} +2 -2
- package/umd/typings/src/library/constructors/{createPromptbookSublibrary.d.ts → createSublibrary.d.ts} +1 -1
- package/umd/typings/src/library/libraryToJson.d.ts +8 -0
- package/umd/typings/src/library/libraryToJson.test.d.ts +1 -0
- package/umd/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -1
- package/esm/typings/src/library/constructors/createPromptbookLibraryFromSources.d.ts +0 -16
- package/umd/typings/src/library/constructors/createPromptbookLibraryFromSources.d.ts +0 -16
- /package/esm/typings/src/library/constructors/{createPromptbookLibraryFromDirectory.test.d.ts → createLibraryFromDirectory.test.d.ts} +0 -0
- /package/esm/typings/src/library/constructors/{createPromptbookLibraryFromPromise.test.d.ts → createLibraryFromJson.test.d.ts} +0 -0
- /package/esm/typings/src/library/constructors/{createPromptbookLibraryFromSources.test.d.ts → createLibraryFromPromise.test.d.ts} +0 -0
- /package/{umd/typings/src/library/constructors/createPromptbookLibraryFromDirectory.test.d.ts → esm/typings/src/library/libraryToJson.test.d.ts} +0 -0
- /package/umd/typings/src/library/constructors/{createPromptbookLibraryFromPromise.test.d.ts → createLibraryFromDirectory.test.d.ts} +0 -0
- /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 `
|
|
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
|
|
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
|
-
* `
|
|
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 `
|
|
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
|
|
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 `
|
|
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
|
|
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
|
|
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
|
|
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-
|
|
3
|
+
"version": "0.59.0-23",
|
|
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-
|
|
55
|
+
"@promptbook/core": "0.59.0-23"
|
|
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('
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', '
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-cli"] = {}, global.
|
|
5
|
-
})(this, (function (exports,
|
|
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,37 @@
|
|
|
147
147
|
/**
|
|
148
148
|
* The version of the Promptbook library
|
|
149
149
|
*/
|
|
150
|
-
var PROMPTBOOK_VERSION = '0.59.0-
|
|
150
|
+
var PROMPTBOOK_VERSION = '0.59.0-21';
|
|
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
|
+
}
|
|
151
181
|
|
|
152
182
|
/**
|
|
153
183
|
* Removes HTML or Markdown comments from a string.
|
|
@@ -226,7 +256,7 @@
|
|
|
226
256
|
return PromptbookSyntaxError;
|
|
227
257
|
}(Error));
|
|
228
258
|
|
|
229
|
-
var promptbookLibrary = [{title:"Prepare Knowledge from Markdown",promptbookUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.59.0-
|
|
259
|
+
var promptbookLibrary = [{title:"Prepare Knowledge from Markdown",promptbookUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.59.0-21",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
260
|
|
|
231
261
|
/**
|
|
232
262
|
* This error indicates errors during the execution of the promptbook
|
|
@@ -1847,6 +1877,7 @@
|
|
|
1847
1877
|
* Library of promptbooks that groups together promptbooks for an application.
|
|
1848
1878
|
* This implementation is a very thin wrapper around the Array / Map of promptbooks.
|
|
1849
1879
|
*
|
|
1880
|
+
* @private use `createLibraryFromJson` instead
|
|
1850
1881
|
* @see https://github.com/webgptorg/promptbook#promptbook-library
|
|
1851
1882
|
*/
|
|
1852
1883
|
var SimplePromptbookLibrary = /** @class */ (function () {
|
|
@@ -1855,8 +1886,9 @@
|
|
|
1855
1886
|
*
|
|
1856
1887
|
* @param promptbooks !!!
|
|
1857
1888
|
*
|
|
1889
|
+
* @private Use instead `createLibraryFromJson`
|
|
1858
1890
|
* Note: During the construction logic of all promptbooks are validated
|
|
1859
|
-
* Note: It is not recommended to use this constructor directly, use `
|
|
1891
|
+
* Note: It is not recommended to use this constructor directly, use `createLibraryFromJson` *(or other variant)* instead
|
|
1860
1892
|
*/
|
|
1861
1893
|
function SimplePromptbookLibrary() {
|
|
1862
1894
|
var e_1, _a;
|
|
@@ -1925,68 +1957,23 @@
|
|
|
1925
1957
|
/**
|
|
1926
1958
|
* Creates PromptbookLibrary from array of PromptbookJson or PromptbookString
|
|
1927
1959
|
*
|
|
1928
|
-
* Note:
|
|
1960
|
+
* Note: Functions `libraryToJson` and `createLibraryFromJson` are complementary
|
|
1929
1961
|
* Note: During the construction syntax and logic of all sources are validated
|
|
1930
1962
|
*
|
|
1931
1963
|
* @param promptbookSources
|
|
1932
1964
|
* @returns PromptbookLibrary
|
|
1933
1965
|
*/
|
|
1934
|
-
function
|
|
1935
|
-
var
|
|
1966
|
+
function createLibraryFromJson() {
|
|
1967
|
+
var promptbooks = [];
|
|
1936
1968
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1937
|
-
|
|
1969
|
+
promptbooks[_i] = arguments[_i];
|
|
1938
1970
|
}
|
|
1939
1971
|
return __awaiter(this, void 0, void 0, function () {
|
|
1940
|
-
|
|
1941
|
-
|
|
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
|
-
}
|
|
1972
|
+
return __generator(this, function (_a) {
|
|
1973
|
+
return [2 /*return*/, new (SimplePromptbookLibrary.bind.apply(SimplePromptbookLibrary, __spreadArray([void 0], __read(promptbooks), false)))()];
|
|
1984
1974
|
});
|
|
1985
1975
|
});
|
|
1986
1976
|
}
|
|
1987
|
-
/**
|
|
1988
|
-
* TODO: !!!! [🧠] Library precompilation and do not mix markdown and json promptbooks
|
|
1989
|
-
*/
|
|
1990
1977
|
|
|
1991
1978
|
/* tslint:disable */
|
|
1992
1979
|
function normalizeToKebabCase(sentence) {
|
|
@@ -2051,7 +2038,7 @@
|
|
|
2051
2038
|
switch (_b.label) {
|
|
2052
2039
|
case 0:
|
|
2053
2040
|
content = options.content, llmTools = options.llmTools, _a = options.isVerbose, isVerbose = _a === void 0 ? false : _a;
|
|
2054
|
-
return [4 /*yield*/,
|
|
2041
|
+
return [4 /*yield*/, createLibraryFromJson.apply(void 0, __spreadArray([], __read(promptbookLibrary), false))];
|
|
2055
2042
|
case 1:
|
|
2056
2043
|
library = _b.sent();
|
|
2057
2044
|
promptbook = library.getPromptbookByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md');
|
|
@@ -3369,117 +3356,105 @@
|
|
|
3369
3356
|
*/
|
|
3370
3357
|
|
|
3371
3358
|
/**
|
|
3372
|
-
*
|
|
3359
|
+
* Initializes `prettify` command for Promptbook CLI utilities
|
|
3360
|
+
*
|
|
3361
|
+
* @private part of `promptbookCli`
|
|
3373
3362
|
*/
|
|
3374
|
-
function
|
|
3363
|
+
function initializePrettify(program) {
|
|
3364
|
+
var _this = this;
|
|
3365
|
+
var prettifyCommand = program.command('prettify');
|
|
3366
|
+
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 "));
|
|
3367
|
+
prettifyCommand.argument('<filesGlob>', 'Promptbooks to prettify as glob pattern');
|
|
3368
|
+
prettifyCommand.option('-i, --ignore <glob>', "Ignore as glob pattern");
|
|
3369
|
+
prettifyCommand.action(function (filesGlob, _a) {
|
|
3370
|
+
var ignore = _a.ignore;
|
|
3371
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
3372
|
+
var filePaths, filePaths_1, filePaths_1_1, filePath, promptbookMarkdown, error_1, e_1_1;
|
|
3373
|
+
var e_1, _b;
|
|
3374
|
+
return __generator(this, function (_c) {
|
|
3375
|
+
switch (_c.label) {
|
|
3376
|
+
case 0: return [4 /*yield*/, glob__default["default"](filesGlob, { ignore: ignore })];
|
|
3377
|
+
case 1:
|
|
3378
|
+
filePaths = _c.sent();
|
|
3379
|
+
_c.label = 2;
|
|
3380
|
+
case 2:
|
|
3381
|
+
_c.trys.push([2, 11, 12, 13]);
|
|
3382
|
+
filePaths_1 = __values(filePaths), filePaths_1_1 = filePaths_1.next();
|
|
3383
|
+
_c.label = 3;
|
|
3384
|
+
case 3:
|
|
3385
|
+
if (!!filePaths_1_1.done) return [3 /*break*/, 10];
|
|
3386
|
+
filePath = filePaths_1_1.value;
|
|
3387
|
+
if (!filePath.endsWith('.ptbk.md')) {
|
|
3388
|
+
console.warn(colors__default["default"].yellow("Skipping prettify of non-promptbook ".concat(filePath)));
|
|
3389
|
+
return [3 /*break*/, 9];
|
|
3390
|
+
}
|
|
3391
|
+
return [4 /*yield*/, promises.readFile(filePath, 'utf-8')];
|
|
3392
|
+
case 4:
|
|
3393
|
+
promptbookMarkdown = (_c.sent());
|
|
3394
|
+
_c.label = 5;
|
|
3395
|
+
case 5:
|
|
3396
|
+
_c.trys.push([5, 8, , 9]);
|
|
3397
|
+
return [4 /*yield*/, prettifyPromptbookString(promptbookMarkdown, {
|
|
3398
|
+
isGraphAdded: true,
|
|
3399
|
+
isPrettifyed: true,
|
|
3400
|
+
// <- [🕌]
|
|
3401
|
+
})];
|
|
3402
|
+
case 6:
|
|
3403
|
+
promptbookMarkdown = _c.sent();
|
|
3404
|
+
return [4 /*yield*/, promises.writeFile(filePath, promptbookMarkdown)];
|
|
3405
|
+
case 7:
|
|
3406
|
+
_c.sent();
|
|
3407
|
+
console.info(colors__default["default"].green("Prettify ".concat(filePath)));
|
|
3408
|
+
return [3 /*break*/, 9];
|
|
3409
|
+
case 8:
|
|
3410
|
+
error_1 = _c.sent();
|
|
3411
|
+
if (!(error_1 instanceof Error)) {
|
|
3412
|
+
throw error_1;
|
|
3413
|
+
}
|
|
3414
|
+
console.info(colors__default["default"].red("Prettify ".concat(error_1.name, " ").concat(filePath)));
|
|
3415
|
+
console.error(colors__default["default"].bgRed(error_1.name));
|
|
3416
|
+
console.error(error_1);
|
|
3417
|
+
process.exit(1);
|
|
3418
|
+
return [3 /*break*/, 9];
|
|
3419
|
+
case 9:
|
|
3420
|
+
filePaths_1_1 = filePaths_1.next();
|
|
3421
|
+
return [3 /*break*/, 3];
|
|
3422
|
+
case 10: return [3 /*break*/, 13];
|
|
3423
|
+
case 11:
|
|
3424
|
+
e_1_1 = _c.sent();
|
|
3425
|
+
e_1 = { error: e_1_1 };
|
|
3426
|
+
return [3 /*break*/, 13];
|
|
3427
|
+
case 12:
|
|
3428
|
+
try {
|
|
3429
|
+
if (filePaths_1_1 && !filePaths_1_1.done && (_b = filePaths_1.return)) _b.call(filePaths_1);
|
|
3430
|
+
}
|
|
3431
|
+
finally { if (e_1) throw e_1.error; }
|
|
3432
|
+
return [7 /*endfinally*/];
|
|
3433
|
+
case 13:
|
|
3434
|
+
process.exit(0);
|
|
3435
|
+
return [2 /*return*/];
|
|
3436
|
+
}
|
|
3437
|
+
});
|
|
3438
|
+
});
|
|
3439
|
+
});
|
|
3440
|
+
}
|
|
3441
|
+
|
|
3442
|
+
/**
|
|
3443
|
+
* Runs CLI utilities of Promptbook package
|
|
3444
|
+
*/
|
|
3445
|
+
function promptbookCli() {
|
|
3375
3446
|
return __awaiter(this, void 0, void 0, function () {
|
|
3376
|
-
var program
|
|
3377
|
-
var _this = this;
|
|
3447
|
+
var program;
|
|
3378
3448
|
return __generator(this, function (_a) {
|
|
3379
3449
|
if (!isRunningInNode()) {
|
|
3380
|
-
throw new Error(spaceTrim.spaceTrim("\n Function
|
|
3450
|
+
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
3451
|
}
|
|
3382
3452
|
program = new commander__default["default"].Command();
|
|
3383
3453
|
program.name('promptbook');
|
|
3384
3454
|
program.version(PROMPTBOOK_VERSION);
|
|
3385
|
-
program.description(spaceTrim.spaceTrim("\n Promptbook utilities\n "));
|
|
3386
|
-
|
|
3387
|
-
|
|
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
|
-
//------
|
|
3455
|
+
program.description(spaceTrim.spaceTrim("\n Promptbook utilities for enhancing workflow with promptbooks\n "));
|
|
3456
|
+
initializeHello(program);
|
|
3457
|
+
initializePrettify(program);
|
|
3483
3458
|
program.parse(process.argv);
|
|
3484
3459
|
return [2 /*return*/];
|
|
3485
3460
|
});
|
|
@@ -3497,7 +3472,7 @@
|
|
|
3497
3472
|
*/
|
|
3498
3473
|
var __ = {
|
|
3499
3474
|
// Note: [🥠]
|
|
3500
|
-
|
|
3475
|
+
promptbookCli: promptbookCli,
|
|
3501
3476
|
};
|
|
3502
3477
|
|
|
3503
3478
|
exports.PROMPTBOOK_VERSION = PROMPTBOOK_VERSION;
|