@promptbook/node 0.59.0-20 → 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.
Files changed (49) hide show
  1. package/esm/index.es.js +32 -75
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/src/_packages/cli.index.d.ts +2 -2
  4. package/esm/typings/src/_packages/core.index.d.ts +6 -6
  5. package/esm/typings/src/_packages/node.index.d.ts +2 -2
  6. package/esm/typings/src/_packages/types.index.d.ts +2 -1
  7. package/esm/typings/src/cli/actions/hello.d.ts +7 -0
  8. package/esm/typings/src/cli/actions/make.d.ts +7 -0
  9. package/esm/typings/src/cli/actions/prettify.d.ts +7 -0
  10. package/esm/typings/src/{conversion/prettify/prettifyPromptbookStringCli.d.ts → cli/promptbookCli.d.ts} +2 -2
  11. package/esm/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +16 -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 +32 -75
  22. package/umd/index.umd.js.map +1 -1
  23. package/umd/typings/src/_packages/cli.index.d.ts +2 -2
  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/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +16 -2
  32. package/umd/typings/src/library/SimplePromptbookLibrary.d.ts +3 -1
  33. package/{esm/typings/src/library/constructors/createPromptbookLibraryFromDirectory.d.ts → umd/typings/src/library/constructors/createLibraryFromDirectory.d.ts} +2 -2
  34. package/umd/typings/src/library/constructors/createLibraryFromJson.d.ts +12 -0
  35. package/{esm/typings/src/library/constructors/createPromptbookLibraryFromPromise.d.ts → umd/typings/src/library/constructors/createLibraryFromPromise.d.ts} +3 -7
  36. package/umd/typings/src/library/constructors/createLibraryFromPromise.test.d.ts +1 -0
  37. package/{esm/typings/src/library/constructors/createPromptbookLibraryFromUrl.d.ts → umd/typings/src/library/constructors/createLibraryFromUrl.d.ts} +2 -2
  38. package/umd/typings/src/library/constructors/{createPromptbookSublibrary.d.ts → createSublibrary.d.ts} +1 -1
  39. package/umd/typings/src/library/libraryToJson.d.ts +8 -0
  40. package/umd/typings/src/library/libraryToJson.test.d.ts +1 -0
  41. package/umd/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -1
  42. package/esm/typings/src/library/constructors/createPromptbookLibraryFromSources.d.ts +0 -16
  43. package/umd/typings/src/library/constructors/createPromptbookLibraryFromSources.d.ts +0 -16
  44. /package/esm/typings/src/library/constructors/{createPromptbookLibraryFromDirectory.test.d.ts → createLibraryFromDirectory.test.d.ts} +0 -0
  45. /package/esm/typings/src/library/constructors/{createPromptbookLibraryFromPromise.test.d.ts → createLibraryFromJson.test.d.ts} +0 -0
  46. /package/esm/typings/src/library/constructors/{createPromptbookLibraryFromSources.test.d.ts → createLibraryFromPromise.test.d.ts} +0 -0
  47. /package/{umd/typings/src/library/constructors/createPromptbookLibraryFromDirectory.test.d.ts → esm/typings/src/library/libraryToJson.test.d.ts} +0 -0
  48. /package/umd/typings/src/library/constructors/{createPromptbookLibraryFromPromise.test.d.ts → createLibraryFromDirectory.test.d.ts} +0 -0
  49. /package/umd/typings/src/library/constructors/{createPromptbookLibraryFromSources.test.d.ts → createLibraryFromJson.test.d.ts} +0 -0
package/esm/index.es.js CHANGED
@@ -137,7 +137,7 @@ var PromptbookSyntaxError = /** @class */ (function (_super) {
137
137
  return PromptbookSyntaxError;
138
138
  }(Error));
139
139
 
140
- var promptbookLibrary = [{title:"Prepare Knowledge from Markdown",promptbookUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.59.0-22",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:[]}];
140
+ 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:[]}];
141
141
 
142
142
  /**
143
143
  * This error indicates errors during the execution of the promptbook
@@ -462,7 +462,7 @@ function isValidJsonString(value /* <-[👨‍⚖️] */) {
462
462
  /**
463
463
  * The version of the Promptbook library
464
464
  */
465
- var PROMPTBOOK_VERSION = '0.59.0-22';
465
+ var PROMPTBOOK_VERSION = '0.59.0-21';
466
466
 
467
467
  /**
468
468
  * Function `addUsage` will add multiple usages into one
@@ -1795,6 +1795,7 @@ var PromptbookReferenceError = /** @class */ (function (_super) {
1795
1795
  * Library of promptbooks that groups together promptbooks for an application.
1796
1796
  * This implementation is a very thin wrapper around the Array / Map of promptbooks.
1797
1797
  *
1798
+ * @private use `createLibraryFromJson` instead
1798
1799
  * @see https://github.com/webgptorg/promptbook#promptbook-library
1799
1800
  */
1800
1801
  var SimplePromptbookLibrary = /** @class */ (function () {
@@ -1803,8 +1804,9 @@ var SimplePromptbookLibrary = /** @class */ (function () {
1803
1804
  *
1804
1805
  * @param promptbooks !!!
1805
1806
  *
1807
+ * @private Use instead `createLibraryFromJson`
1806
1808
  * Note: During the construction logic of all promptbooks are validated
1807
- * Note: It is not recommended to use this constructor directly, use `createPromptbookLibraryFromSources` *(or other variant)* instead
1809
+ * Note: It is not recommended to use this constructor directly, use `createLibraryFromJson` *(or other variant)* instead
1808
1810
  */
1809
1811
  function SimplePromptbookLibrary() {
1810
1812
  var e_1, _a;
@@ -1873,68 +1875,23 @@ var SimplePromptbookLibrary = /** @class */ (function () {
1873
1875
  /**
1874
1876
  * Creates PromptbookLibrary from array of PromptbookJson or PromptbookString
1875
1877
  *
1876
- * Note: You can combine `PromptbookString` (`.ptbk.md`) with `PromptbookJson` BUT it is not recommended
1878
+ * Note: Functions `libraryToJson` and `createLibraryFromJson` are complementary
1877
1879
  * Note: During the construction syntax and logic of all sources are validated
1878
1880
  *
1879
1881
  * @param promptbookSources
1880
1882
  * @returns PromptbookLibrary
1881
1883
  */
1882
- function createPromptbookLibraryFromSources() {
1883
- var promptbookSources = [];
1884
+ function createLibraryFromJson() {
1885
+ var promptbooks = [];
1884
1886
  for (var _i = 0; _i < arguments.length; _i++) {
1885
- promptbookSources[_i] = arguments[_i];
1887
+ promptbooks[_i] = arguments[_i];
1886
1888
  }
1887
1889
  return __awaiter(this, void 0, void 0, function () {
1888
- var promptbooks, promptbookSources_1, promptbookSources_1_1, source, promptbook, e_1_1;
1889
- var e_1, _a;
1890
- return __generator(this, function (_b) {
1891
- switch (_b.label) {
1892
- case 0:
1893
- promptbooks = new Array();
1894
- _b.label = 1;
1895
- case 1:
1896
- _b.trys.push([1, 8, 9, 10]);
1897
- promptbookSources_1 = __values(promptbookSources), promptbookSources_1_1 = promptbookSources_1.next();
1898
- _b.label = 2;
1899
- case 2:
1900
- if (!!promptbookSources_1_1.done) return [3 /*break*/, 7];
1901
- source = promptbookSources_1_1.value;
1902
- promptbook = void 0;
1903
- if (!(typeof source === 'string')) return [3 /*break*/, 4];
1904
- return [4 /*yield*/, promptbookStringToJson(source)];
1905
- case 3:
1906
- // Note: When directly creating from string, no need to validate the source
1907
- // The validation is performed always before execution
1908
- promptbook = _b.sent();
1909
- return [3 /*break*/, 5];
1910
- case 4:
1911
- promptbook = source;
1912
- _b.label = 5;
1913
- case 5:
1914
- promptbooks.push(promptbook);
1915
- _b.label = 6;
1916
- case 6:
1917
- promptbookSources_1_1 = promptbookSources_1.next();
1918
- return [3 /*break*/, 2];
1919
- case 7: return [3 /*break*/, 10];
1920
- case 8:
1921
- e_1_1 = _b.sent();
1922
- e_1 = { error: e_1_1 };
1923
- return [3 /*break*/, 10];
1924
- case 9:
1925
- try {
1926
- if (promptbookSources_1_1 && !promptbookSources_1_1.done && (_a = promptbookSources_1.return)) _a.call(promptbookSources_1);
1927
- }
1928
- finally { if (e_1) throw e_1.error; }
1929
- return [7 /*endfinally*/];
1930
- case 10: return [2 /*return*/, new (SimplePromptbookLibrary.bind.apply(SimplePromptbookLibrary, __spreadArray([void 0], __read(promptbooks), false)))()];
1931
- }
1890
+ return __generator(this, function (_a) {
1891
+ return [2 /*return*/, new (SimplePromptbookLibrary.bind.apply(SimplePromptbookLibrary, __spreadArray([void 0], __read(promptbooks), false)))()];
1932
1892
  });
1933
1893
  });
1934
1894
  }
1935
- /**
1936
- * TODO: !!!! [🧠] Library precompilation and do not mix markdown and json promptbooks
1937
- */
1938
1895
 
1939
1896
  /* tslint:disable */
1940
1897
  function normalizeToKebabCase(sentence) {
@@ -1993,15 +1950,15 @@ function normalizeToKebabCase(sentence) {
1993
1950
 
1994
1951
  function prepareKnowledgeFromMarkdown(options) {
1995
1952
  return __awaiter(this, void 0, void 0, function () {
1996
- var content, llmTools, library, promptbook, executor, result, outputParameters, knowledgeRaw, knowledgeTextPieces, knowledge;
1953
+ var content, llmTools, _a, isVerbose, library, promptbook, executor, result, outputParameters, knowledgeRaw, knowledgeTextPieces, knowledge;
1997
1954
  var _this = this;
1998
- return __generator(this, function (_a) {
1999
- switch (_a.label) {
1955
+ return __generator(this, function (_b) {
1956
+ switch (_b.label) {
2000
1957
  case 0:
2001
- content = options.content, llmTools = options.llmTools;
2002
- return [4 /*yield*/, createPromptbookLibraryFromSources.apply(void 0, __spreadArray([], __read(promptbookLibrary), false))];
1958
+ content = options.content, llmTools = options.llmTools, _a = options.isVerbose, isVerbose = _a === void 0 ? false : _a;
1959
+ return [4 /*yield*/, createLibraryFromJson.apply(void 0, __spreadArray([], __read(promptbookLibrary), false))];
2003
1960
  case 1:
2004
- library = _a.sent();
1961
+ library = _b.sent();
2005
1962
  promptbook = library.getPromptbookByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md');
2006
1963
  executor = createPromptbookExecutor({
2007
1964
  promptbook: promptbook,
@@ -2014,11 +1971,14 @@ function prepareKnowledgeFromMarkdown(options) {
2014
1971
  });
2015
1972
  return [4 /*yield*/, executor({ content: content })];
2016
1973
  case 2:
2017
- result = _a.sent();
1974
+ result = _b.sent();
2018
1975
  assertsExecutionSuccessful(result);
2019
1976
  outputParameters = result.outputParameters;
2020
1977
  knowledgeRaw = outputParameters.knowledge;
2021
1978
  knowledgeTextPieces = (knowledgeRaw || '').split('\n---\n');
1979
+ if (isVerbose) {
1980
+ console.info('knowledgeTextPieces:', knowledgeTextPieces);
1981
+ }
2022
1982
  return [4 /*yield*/, Promise.all(knowledgeTextPieces.map(function (knowledgeTextPiece, i) { return __awaiter(_this, void 0, void 0, function () {
2023
1983
  var name, title, content, keywords, index, sources;
2024
1984
  return __generator(this, function (_a) {
@@ -2050,7 +2010,7 @@ function prepareKnowledgeFromMarkdown(options) {
2050
2010
  });
2051
2011
  }); }))];
2052
2012
  case 3:
2053
- knowledge = _a.sent();
2013
+ knowledge = _b.sent();
2054
2014
  return [2 /*return*/, knowledge];
2055
2015
  }
2056
2016
  });
@@ -3205,19 +3165,19 @@ new Function("\n try {\n if (typeof WorkerGlobalScope !== 'undefined'
3205
3165
  * - Factory function that returns Promise of array of PromptbookJson or PromptbookString
3206
3166
  *
3207
3167
  * Note: This is useful as internal tool for other constructor functions like
3208
- * `createPromptbookLibraryFromUrl` or `createPromptbookLibraryFromDirectory`
3168
+ * `createLibraryFromUrl` or `createLibraryFromDirectory`
3209
3169
  * Consider using those functions instead of this one
3210
3170
  *
3211
3171
  * Note: The function does NOT return promise it returns the library directly which waits for the sources to be resolved
3212
3172
  * when error occurs in given promise or factory function, it is thrown during `listPromptbooks` or `getPromptbookByUrl` call
3213
3173
  *
3214
- * Note: Consider using `createPromptbookLibraryFromDirectory` or `createPromptbookLibraryFromUrl`
3174
+ * Note: Consider using `createLibraryFromDirectory` or `createLibraryFromUrl`
3215
3175
  *
3216
3176
  * @param promptbookSourcesPromiseOrFactory
3217
3177
  * @returns PromptbookLibrary
3218
3178
  * @deprecated Do not use, it will became internal tool for other constructor functions
3219
3179
  */
3220
- function createPromptbookLibraryFromPromise(promptbookSourcesPromiseOrFactory) {
3180
+ function createLibraryFromPromise(promptbookSourcesPromiseOrFactory) {
3221
3181
  var library;
3222
3182
  function forSources() {
3223
3183
  return __awaiter(this, void 0, void 0, function () {
@@ -3232,7 +3192,7 @@ function createPromptbookLibraryFromPromise(promptbookSourcesPromiseOrFactory) {
3232
3192
  return [4 /*yield*/, promptbookSourcesPromiseOrFactory];
3233
3193
  case 1:
3234
3194
  promptbookSources = _a.sent();
3235
- return [4 /*yield*/, createPromptbookLibraryFromSources.apply(void 0, __spreadArray([], __read(promptbookSources), false))];
3195
+ return [4 /*yield*/, createLibraryFromJson.apply(void 0, __spreadArray([], __read(promptbookSources), false))];
3236
3196
  case 2:
3237
3197
  library = _a.sent();
3238
3198
  return [2 /*return*/];
@@ -3282,9 +3242,6 @@ function createPromptbookLibraryFromPromise(promptbookSourcesPromiseOrFactory) {
3282
3242
  isResponsibleForPrompt: isResponsibleForPrompt,
3283
3243
  };
3284
3244
  }
3285
- /**
3286
- * TODO: !!!! [🧠] Library precompilation and do not mix markdown and json promptbooks
3287
- */
3288
3245
 
3289
3246
  /**
3290
3247
  * Constructs Promptbook from given directory
@@ -3295,7 +3252,7 @@ function createPromptbookLibraryFromPromise(promptbookSourcesPromiseOrFactory) {
3295
3252
  * @param options - Misc options for the library
3296
3253
  * @returns PromptbookLibrary
3297
3254
  */
3298
- function createPromptbookLibraryFromDirectory(path, options) {
3255
+ function createLibraryFromDirectory(path, options) {
3299
3256
  return __awaiter(this, void 0, void 0, function () {
3300
3257
  var _a, _b, isRecursive, _c, isVerbose, _d, isLazyLoaded, _e, isCrashOnError, library;
3301
3258
  var _this = this;
@@ -3303,10 +3260,10 @@ function createPromptbookLibraryFromDirectory(path, options) {
3303
3260
  switch (_f.label) {
3304
3261
  case 0:
3305
3262
  if (!isRunningInNode()) {
3306
- throw new Error('Function `createPromptbookLibraryFromDirectory` can only be run in Node.js environment because it reads the file system.');
3263
+ throw new Error('Function `createLibraryFromDirectory` can only be run in Node.js environment because it reads the file system.');
3307
3264
  }
3308
3265
  _a = options || {}, _b = _a.isRecursive, isRecursive = _b === void 0 ? true : _b, _c = _a.isVerbose, isVerbose = _c === void 0 ? false : _c, _d = _a.isLazyLoaded, isLazyLoaded = _d === void 0 ? false : _d, _e = _a.isCrashOnError, isCrashOnError = _e === void 0 ? true : _e;
3309
- library = createPromptbookLibraryFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
3266
+ library = createLibraryFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
3310
3267
  var fileNames, promptbooks, _loop_1, fileNames_1, fileNames_1_1, fileName, e_1_1;
3311
3268
  var e_1, _a;
3312
3269
  return __generator(this, function (_b) {
@@ -3319,7 +3276,7 @@ function createPromptbookLibraryFromDirectory(path, options) {
3319
3276
  case 1:
3320
3277
  fileNames = _b.sent();
3321
3278
  if (isVerbose) {
3322
- console.info('createPromptbookLibraryFromDirectory', { path: path, isRecursive: isRecursive, fileNames: fileNames });
3279
+ console.info('createLibraryFromDirectory', { path: path, isRecursive: isRecursive, fileNames: fileNames });
3323
3280
  }
3324
3281
  promptbooks = [];
3325
3282
  _loop_1 = function (fileName) {
@@ -3436,7 +3393,7 @@ function createPromptbookLibraryFromDirectory(path, options) {
3436
3393
  * @param path
3437
3394
  * @param isRecursive
3438
3395
  * @returns List of all files in the directory
3439
- * @private internal function for `createPromptbookLibraryFromDirectory`
3396
+ * @private internal function for `createLibraryFromDirectory`
3440
3397
  */
3441
3398
  function listAllFiles(path, isRecursive) {
3442
3399
  return __awaiter(this, void 0, void 0, function () {
@@ -3493,5 +3450,5 @@ function listAllFiles(path, isRecursive) {
3493
3450
  * TODO: !!!! [🧠] Library precompilation and do not mix markdown and json promptbooks
3494
3451
  */
3495
3452
 
3496
- export { PROMPTBOOK_VERSION, createPromptbookLibraryFromDirectory };
3453
+ export { PROMPTBOOK_VERSION, createLibraryFromDirectory };
3497
3454
  //# sourceMappingURL=index.es.js.map