@promptbook/core 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 +52 -73
  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 +1 -1
  21. package/umd/index.umd.js +56 -77
  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
@@ -199,7 +199,7 @@ var PromptbookSyntaxError = /** @class */ (function (_super) {
199
199
  return PromptbookSyntaxError;
200
200
  }(Error));
201
201
 
202
- 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:[]}];
202
+ 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:[]}];
203
203
 
204
204
  /**
205
205
  * This error indicates errors during the execution of the promptbook
@@ -524,7 +524,7 @@ function isValidJsonString(value /* <-[👨‍⚖️] */) {
524
524
  /**
525
525
  * The version of the Promptbook library
526
526
  */
527
- var PROMPTBOOK_VERSION = '0.59.0-22';
527
+ var PROMPTBOOK_VERSION = '0.59.0-21';
528
528
 
529
529
  /**
530
530
  * Function `addUsage` will add multiple usages into one
@@ -1846,6 +1846,7 @@ var PromptbookReferenceError = /** @class */ (function (_super) {
1846
1846
  * Library of promptbooks that groups together promptbooks for an application.
1847
1847
  * This implementation is a very thin wrapper around the Array / Map of promptbooks.
1848
1848
  *
1849
+ * @private use `createLibraryFromJson` instead
1849
1850
  * @see https://github.com/webgptorg/promptbook#promptbook-library
1850
1851
  */
1851
1852
  var SimplePromptbookLibrary = /** @class */ (function () {
@@ -1854,8 +1855,9 @@ var SimplePromptbookLibrary = /** @class */ (function () {
1854
1855
  *
1855
1856
  * @param promptbooks !!!
1856
1857
  *
1858
+ * @private Use instead `createLibraryFromJson`
1857
1859
  * Note: During the construction logic of all promptbooks are validated
1858
- * Note: It is not recommended to use this constructor directly, use `createPromptbookLibraryFromSources` *(or other variant)* instead
1860
+ * Note: It is not recommended to use this constructor directly, use `createLibraryFromJson` *(or other variant)* instead
1859
1861
  */
1860
1862
  function SimplePromptbookLibrary() {
1861
1863
  var e_1, _a;
@@ -1924,68 +1926,23 @@ var SimplePromptbookLibrary = /** @class */ (function () {
1924
1926
  /**
1925
1927
  * Creates PromptbookLibrary from array of PromptbookJson or PromptbookString
1926
1928
  *
1927
- * Note: You can combine `PromptbookString` (`.ptbk.md`) with `PromptbookJson` BUT it is not recommended
1929
+ * Note: Functions `libraryToJson` and `createLibraryFromJson` are complementary
1928
1930
  * Note: During the construction syntax and logic of all sources are validated
1929
1931
  *
1930
1932
  * @param promptbookSources
1931
1933
  * @returns PromptbookLibrary
1932
1934
  */
1933
- function createPromptbookLibraryFromSources() {
1934
- var promptbookSources = [];
1935
+ function createLibraryFromJson() {
1936
+ var promptbooks = [];
1935
1937
  for (var _i = 0; _i < arguments.length; _i++) {
1936
- promptbookSources[_i] = arguments[_i];
1938
+ promptbooks[_i] = arguments[_i];
1937
1939
  }
1938
1940
  return __awaiter(this, void 0, void 0, function () {
1939
- var promptbooks, promptbookSources_1, promptbookSources_1_1, source, promptbook, e_1_1;
1940
- var e_1, _a;
1941
- return __generator(this, function (_b) {
1942
- switch (_b.label) {
1943
- case 0:
1944
- promptbooks = new Array();
1945
- _b.label = 1;
1946
- case 1:
1947
- _b.trys.push([1, 8, 9, 10]);
1948
- promptbookSources_1 = __values(promptbookSources), promptbookSources_1_1 = promptbookSources_1.next();
1949
- _b.label = 2;
1950
- case 2:
1951
- if (!!promptbookSources_1_1.done) return [3 /*break*/, 7];
1952
- source = promptbookSources_1_1.value;
1953
- promptbook = void 0;
1954
- if (!(typeof source === 'string')) return [3 /*break*/, 4];
1955
- return [4 /*yield*/, promptbookStringToJson(source)];
1956
- case 3:
1957
- // Note: When directly creating from string, no need to validate the source
1958
- // The validation is performed always before execution
1959
- promptbook = _b.sent();
1960
- return [3 /*break*/, 5];
1961
- case 4:
1962
- promptbook = source;
1963
- _b.label = 5;
1964
- case 5:
1965
- promptbooks.push(promptbook);
1966
- _b.label = 6;
1967
- case 6:
1968
- promptbookSources_1_1 = promptbookSources_1.next();
1969
- return [3 /*break*/, 2];
1970
- case 7: return [3 /*break*/, 10];
1971
- case 8:
1972
- e_1_1 = _b.sent();
1973
- e_1 = { error: e_1_1 };
1974
- return [3 /*break*/, 10];
1975
- case 9:
1976
- try {
1977
- if (promptbookSources_1_1 && !promptbookSources_1_1.done && (_a = promptbookSources_1.return)) _a.call(promptbookSources_1);
1978
- }
1979
- finally { if (e_1) throw e_1.error; }
1980
- return [7 /*endfinally*/];
1981
- case 10: return [2 /*return*/, new (SimplePromptbookLibrary.bind.apply(SimplePromptbookLibrary, __spreadArray([void 0], __read(promptbooks), false)))()];
1982
- }
1941
+ return __generator(this, function (_a) {
1942
+ return [2 /*return*/, new (SimplePromptbookLibrary.bind.apply(SimplePromptbookLibrary, __spreadArray([void 0], __read(promptbooks), false)))()];
1983
1943
  });
1984
1944
  });
1985
1945
  }
1986
- /**
1987
- * TODO: !!!! [🧠] Library precompilation and do not mix markdown and json promptbooks
1988
- */
1989
1946
 
1990
1947
  /* tslint:disable */
1991
1948
  function normalizeToKebabCase(sentence) {
@@ -2044,15 +2001,15 @@ function normalizeToKebabCase(sentence) {
2044
2001
 
2045
2002
  function prepareKnowledgeFromMarkdown(options) {
2046
2003
  return __awaiter(this, void 0, void 0, function () {
2047
- var content, llmTools, library, promptbook, executor, result, outputParameters, knowledgeRaw, knowledgeTextPieces, knowledge;
2004
+ var content, llmTools, _a, isVerbose, library, promptbook, executor, result, outputParameters, knowledgeRaw, knowledgeTextPieces, knowledge;
2048
2005
  var _this = this;
2049
- return __generator(this, function (_a) {
2050
- switch (_a.label) {
2006
+ return __generator(this, function (_b) {
2007
+ switch (_b.label) {
2051
2008
  case 0:
2052
- content = options.content, llmTools = options.llmTools;
2053
- return [4 /*yield*/, createPromptbookLibraryFromSources.apply(void 0, __spreadArray([], __read(promptbookLibrary), false))];
2009
+ content = options.content, llmTools = options.llmTools, _a = options.isVerbose, isVerbose = _a === void 0 ? false : _a;
2010
+ return [4 /*yield*/, createLibraryFromJson.apply(void 0, __spreadArray([], __read(promptbookLibrary), false))];
2054
2011
  case 1:
2055
- library = _a.sent();
2012
+ library = _b.sent();
2056
2013
  promptbook = library.getPromptbookByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md');
2057
2014
  executor = createPromptbookExecutor({
2058
2015
  promptbook: promptbook,
@@ -2065,11 +2022,14 @@ function prepareKnowledgeFromMarkdown(options) {
2065
2022
  });
2066
2023
  return [4 /*yield*/, executor({ content: content })];
2067
2024
  case 2:
2068
- result = _a.sent();
2025
+ result = _b.sent();
2069
2026
  assertsExecutionSuccessful(result);
2070
2027
  outputParameters = result.outputParameters;
2071
2028
  knowledgeRaw = outputParameters.knowledge;
2072
2029
  knowledgeTextPieces = (knowledgeRaw || '').split('\n---\n');
2030
+ if (isVerbose) {
2031
+ console.info('knowledgeTextPieces:', knowledgeTextPieces);
2032
+ }
2073
2033
  return [4 /*yield*/, Promise.all(knowledgeTextPieces.map(function (knowledgeTextPiece, i) { return __awaiter(_this, void 0, void 0, function () {
2074
2034
  var name, title, content, keywords, index, sources;
2075
2035
  return __generator(this, function (_a) {
@@ -2101,7 +2061,7 @@ function prepareKnowledgeFromMarkdown(options) {
2101
2061
  });
2102
2062
  }); }))];
2103
2063
  case 3:
2104
- knowledge = _a.sent();
2064
+ knowledge = _b.sent();
2105
2065
  return [2 /*return*/, knowledge];
2106
2066
  }
2107
2067
  });
@@ -3482,19 +3442,19 @@ var SimplePromptInterfaceTools = /** @class */ (function () {
3482
3442
  * - Factory function that returns Promise of array of PromptbookJson or PromptbookString
3483
3443
  *
3484
3444
  * Note: This is useful as internal tool for other constructor functions like
3485
- * `createPromptbookLibraryFromUrl` or `createPromptbookLibraryFromDirectory`
3445
+ * `createLibraryFromUrl` or `createLibraryFromDirectory`
3486
3446
  * Consider using those functions instead of this one
3487
3447
  *
3488
3448
  * Note: The function does NOT return promise it returns the library directly which waits for the sources to be resolved
3489
3449
  * when error occurs in given promise or factory function, it is thrown during `listPromptbooks` or `getPromptbookByUrl` call
3490
3450
  *
3491
- * Note: Consider using `createPromptbookLibraryFromDirectory` or `createPromptbookLibraryFromUrl`
3451
+ * Note: Consider using `createLibraryFromDirectory` or `createLibraryFromUrl`
3492
3452
  *
3493
3453
  * @param promptbookSourcesPromiseOrFactory
3494
3454
  * @returns PromptbookLibrary
3495
3455
  * @deprecated Do not use, it will became internal tool for other constructor functions
3496
3456
  */
3497
- function createPromptbookLibraryFromPromise(promptbookSourcesPromiseOrFactory) {
3457
+ function createLibraryFromPromise(promptbookSourcesPromiseOrFactory) {
3498
3458
  var library;
3499
3459
  function forSources() {
3500
3460
  return __awaiter(this, void 0, void 0, function () {
@@ -3509,7 +3469,7 @@ function createPromptbookLibraryFromPromise(promptbookSourcesPromiseOrFactory) {
3509
3469
  return [4 /*yield*/, promptbookSourcesPromiseOrFactory];
3510
3470
  case 1:
3511
3471
  promptbookSources = _a.sent();
3512
- return [4 /*yield*/, createPromptbookLibraryFromSources.apply(void 0, __spreadArray([], __read(promptbookSources), false))];
3472
+ return [4 /*yield*/, createLibraryFromJson.apply(void 0, __spreadArray([], __read(promptbookSources), false))];
3513
3473
  case 2:
3514
3474
  library = _a.sent();
3515
3475
  return [2 /*return*/];
@@ -3559,16 +3519,13 @@ function createPromptbookLibraryFromPromise(promptbookSourcesPromiseOrFactory) {
3559
3519
  isResponsibleForPrompt: isResponsibleForPrompt,
3560
3520
  };
3561
3521
  }
3562
- /**
3563
- * TODO: !!!! [🧠] Library precompilation and do not mix markdown and json promptbooks
3564
- */
3565
3522
 
3566
3523
  /**
3567
3524
  * Constructs Promptbook from remote Promptbase URL
3568
3525
 
3569
3526
  * @returns PromptbookLibrary
3570
3527
  */
3571
- function createPromptbookLibraryFromUrl(url, options) {
3528
+ function createLibraryFromUrl(url, options) {
3572
3529
  return __awaiter(this, void 0, void 0, function () {
3573
3530
  var _a, _b, isVerbose, _c, isLazyLoaded, library;
3574
3531
  var _this = this;
@@ -3576,7 +3533,7 @@ function createPromptbookLibraryFromUrl(url, options) {
3576
3533
  switch (_d.label) {
3577
3534
  case 0:
3578
3535
  _a = options || {}, _b = _a.isVerbose, isVerbose = _b === void 0 ? false : _b, _c = _a.isLazyLoaded, isLazyLoaded = _c === void 0 ? false : _c;
3579
- library = createPromptbookLibraryFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
3536
+ library = createLibraryFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
3580
3537
  return __generator(this, function (_a) {
3581
3538
  if (isVerbose) {
3582
3539
  console.info("Creating promptbook library from url ".concat(url.toString()));
@@ -3607,7 +3564,7 @@ function createPromptbookLibraryFromUrl(url, options) {
3607
3564
  * @param promptbookSources
3608
3565
  * @returns PromptbookLibrary
3609
3566
  */
3610
- function createPromptbookSublibrary(library, predicate) {
3567
+ function createSublibrary(library, predicate) {
3611
3568
  function listPromptbooks() {
3612
3569
  return __awaiter(this, void 0, void 0, function () {
3613
3570
  var promptbooks;
@@ -3677,6 +3634,28 @@ function createPromptbookSublibrary(library, predicate) {
3677
3634
  };
3678
3635
  }
3679
3636
 
3637
+ /**
3638
+ * Converts PromptbookLibrary to serialized JSON
3639
+ *
3640
+ * Note: Functions `libraryToJson` and `createLibraryFromJson` are complementary
3641
+ */
3642
+ function libraryToJson(library) {
3643
+ return __awaiter(this, void 0, void 0, function () {
3644
+ var promptbookUrls, promptbooks;
3645
+ return __generator(this, function (_a) {
3646
+ switch (_a.label) {
3647
+ case 0: return [4 /*yield*/, library.listPromptbooks()];
3648
+ case 1:
3649
+ promptbookUrls = _a.sent();
3650
+ return [4 /*yield*/, Promise.all(promptbookUrls.map(function (url) { return library.getPromptbookByUrl(url); }))];
3651
+ case 2:
3652
+ promptbooks = _a.sent();
3653
+ return [2 /*return*/, promptbooks];
3654
+ }
3655
+ });
3656
+ });
3657
+ }
3658
+
3680
3659
  /**
3681
3660
  * Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
3682
3661
  *
@@ -4111,5 +4090,5 @@ function executionReportJsonToString(executionReportJson, options) {
4111
4090
  * TODO: [🧠] Allow to filter out some parts of the report by options
4112
4091
  */
4113
4092
 
4114
- export { CallbackInterfaceTools, ExecutionReportStringOptionsDefaults, ExecutionTypes, ExpectError, MultipleLlmExecutionTools, PROMPTBOOK_VERSION, PromptbookExecutionError, PromptbookLibraryError, PromptbookLogicError, PromptbookNotFoundError, PromptbookReferenceError, PromptbookSyntaxError, SimplePromptInterfaceTools, SimplePromptbookLibrary, TemplateError, UnexpectedError, addUsage, assertsExecutionSuccessful, checkExpectations, createPromptbookExecutor, createPromptbookLibraryFromPromise, createPromptbookLibraryFromSources, createPromptbookLibraryFromUrl, createPromptbookSublibrary, executionReportJsonToString, isPassingExpectations, prepareKnowledgeFromMarkdown, prettifyPromptbookString, promptbookJsonToString, promptbookStringToJson, usageToWorktime, validatePromptbookJson };
4093
+ export { CallbackInterfaceTools, ExecutionReportStringOptionsDefaults, ExecutionTypes, ExpectError, MultipleLlmExecutionTools, PROMPTBOOK_VERSION, PromptbookExecutionError, PromptbookLibraryError, PromptbookLogicError, PromptbookNotFoundError, PromptbookReferenceError, PromptbookSyntaxError, SimplePromptInterfaceTools, TemplateError, UnexpectedError, addUsage, assertsExecutionSuccessful, checkExpectations, createLibraryFromJson, createLibraryFromPromise, createLibraryFromUrl, createPromptbookExecutor, createSublibrary, executionReportJsonToString, isPassingExpectations, libraryToJson, prepareKnowledgeFromMarkdown, prettifyPromptbookString, promptbookJsonToString, promptbookStringToJson, usageToWorktime, validatePromptbookJson };
4115
4094
  //# sourceMappingURL=index.es.js.map