@promptbook/core 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 (47) hide show
  1. package/esm/index.es.js +42 -66
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/src/_packages/cli.index.d.ts +4 -4
  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/library/SimplePromptbookLibrary.d.ts +3 -1
  12. package/{umd/typings/src/library/constructors/createPromptbookLibraryFromDirectory.d.ts → esm/typings/src/library/constructors/createLibraryFromDirectory.d.ts} +2 -2
  13. package/esm/typings/src/library/constructors/createLibraryFromJson.d.ts +12 -0
  14. package/{umd/typings/src/library/constructors/createPromptbookLibraryFromPromise.d.ts → esm/typings/src/library/constructors/createLibraryFromPromise.d.ts} +3 -7
  15. package/{umd/typings/src/library/constructors/createPromptbookLibraryFromUrl.d.ts → esm/typings/src/library/constructors/createLibraryFromUrl.d.ts} +2 -2
  16. package/esm/typings/src/library/constructors/{createPromptbookSublibrary.d.ts → createSublibrary.d.ts} +1 -1
  17. package/esm/typings/src/library/libraryToJson.d.ts +8 -0
  18. package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -1
  19. package/package.json +1 -1
  20. package/umd/index.umd.js +46 -70
  21. package/umd/index.umd.js.map +1 -1
  22. package/umd/typings/src/_packages/cli.index.d.ts +4 -4
  23. package/umd/typings/src/_packages/core.index.d.ts +6 -6
  24. package/umd/typings/src/_packages/node.index.d.ts +2 -2
  25. package/umd/typings/src/_packages/types.index.d.ts +2 -1
  26. package/umd/typings/src/cli/actions/hello.d.ts +7 -0
  27. package/umd/typings/src/cli/actions/make.d.ts +7 -0
  28. package/umd/typings/src/cli/actions/prettify.d.ts +7 -0
  29. package/umd/typings/src/{conversion/prettify/prettifyPromptbookStringCli.d.ts → cli/promptbookCli.d.ts} +2 -2
  30. package/umd/typings/src/library/SimplePromptbookLibrary.d.ts +3 -1
  31. package/{esm/typings/src/library/constructors/createPromptbookLibraryFromDirectory.d.ts → umd/typings/src/library/constructors/createLibraryFromDirectory.d.ts} +2 -2
  32. package/umd/typings/src/library/constructors/createLibraryFromJson.d.ts +12 -0
  33. package/{esm/typings/src/library/constructors/createPromptbookLibraryFromPromise.d.ts → umd/typings/src/library/constructors/createLibraryFromPromise.d.ts} +3 -7
  34. package/umd/typings/src/library/constructors/createLibraryFromPromise.test.d.ts +1 -0
  35. package/{esm/typings/src/library/constructors/createPromptbookLibraryFromUrl.d.ts → umd/typings/src/library/constructors/createLibraryFromUrl.d.ts} +2 -2
  36. package/umd/typings/src/library/constructors/{createPromptbookSublibrary.d.ts → createSublibrary.d.ts} +1 -1
  37. package/umd/typings/src/library/libraryToJson.d.ts +8 -0
  38. package/umd/typings/src/library/libraryToJson.test.d.ts +1 -0
  39. package/umd/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -1
  40. package/esm/typings/src/library/constructors/createPromptbookLibraryFromSources.d.ts +0 -16
  41. package/umd/typings/src/library/constructors/createPromptbookLibraryFromSources.d.ts +0 -16
  42. /package/esm/typings/src/library/constructors/{createPromptbookLibraryFromDirectory.test.d.ts → createLibraryFromDirectory.test.d.ts} +0 -0
  43. /package/esm/typings/src/library/constructors/{createPromptbookLibraryFromPromise.test.d.ts → createLibraryFromJson.test.d.ts} +0 -0
  44. /package/esm/typings/src/library/constructors/{createPromptbookLibraryFromSources.test.d.ts → createLibraryFromPromise.test.d.ts} +0 -0
  45. /package/{umd/typings/src/library/constructors/createPromptbookLibraryFromDirectory.test.d.ts → esm/typings/src/library/libraryToJson.test.d.ts} +0 -0
  46. /package/umd/typings/src/library/constructors/{createPromptbookLibraryFromPromise.test.d.ts → createLibraryFromDirectory.test.d.ts} +0 -0
  47. /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-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:[]}];
202
+ 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:[]}];
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-20';
527
+ var PROMPTBOOK_VERSION = '0.59.0-23';
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) {
@@ -2050,7 +2007,7 @@ function prepareKnowledgeFromMarkdown(options) {
2050
2007
  switch (_b.label) {
2051
2008
  case 0:
2052
2009
  content = options.content, llmTools = options.llmTools, _a = options.isVerbose, isVerbose = _a === void 0 ? false : _a;
2053
- return [4 /*yield*/, createPromptbookLibraryFromSources.apply(void 0, __spreadArray([], __read(promptbookLibrary), false))];
2010
+ return [4 /*yield*/, createLibraryFromJson.apply(void 0, __spreadArray([], __read(promptbookLibrary), false))];
2054
2011
  case 1:
2055
2012
  library = _b.sent();
2056
2013
  promptbook = library.getPromptbookByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md');
@@ -3485,19 +3442,19 @@ var SimplePromptInterfaceTools = /** @class */ (function () {
3485
3442
  * - Factory function that returns Promise of array of PromptbookJson or PromptbookString
3486
3443
  *
3487
3444
  * Note: This is useful as internal tool for other constructor functions like
3488
- * `createPromptbookLibraryFromUrl` or `createPromptbookLibraryFromDirectory`
3445
+ * `createLibraryFromUrl` or `createLibraryFromDirectory`
3489
3446
  * Consider using those functions instead of this one
3490
3447
  *
3491
3448
  * Note: The function does NOT return promise it returns the library directly which waits for the sources to be resolved
3492
3449
  * when error occurs in given promise or factory function, it is thrown during `listPromptbooks` or `getPromptbookByUrl` call
3493
3450
  *
3494
- * Note: Consider using `createPromptbookLibraryFromDirectory` or `createPromptbookLibraryFromUrl`
3451
+ * Note: Consider using `createLibraryFromDirectory` or `createLibraryFromUrl`
3495
3452
  *
3496
3453
  * @param promptbookSourcesPromiseOrFactory
3497
3454
  * @returns PromptbookLibrary
3498
3455
  * @deprecated Do not use, it will became internal tool for other constructor functions
3499
3456
  */
3500
- function createPromptbookLibraryFromPromise(promptbookSourcesPromiseOrFactory) {
3457
+ function createLibraryFromPromise(promptbookSourcesPromiseOrFactory) {
3501
3458
  var library;
3502
3459
  function forSources() {
3503
3460
  return __awaiter(this, void 0, void 0, function () {
@@ -3512,7 +3469,7 @@ function createPromptbookLibraryFromPromise(promptbookSourcesPromiseOrFactory) {
3512
3469
  return [4 /*yield*/, promptbookSourcesPromiseOrFactory];
3513
3470
  case 1:
3514
3471
  promptbookSources = _a.sent();
3515
- return [4 /*yield*/, createPromptbookLibraryFromSources.apply(void 0, __spreadArray([], __read(promptbookSources), false))];
3472
+ return [4 /*yield*/, createLibraryFromJson.apply(void 0, __spreadArray([], __read(promptbookSources), false))];
3516
3473
  case 2:
3517
3474
  library = _a.sent();
3518
3475
  return [2 /*return*/];
@@ -3562,16 +3519,13 @@ function createPromptbookLibraryFromPromise(promptbookSourcesPromiseOrFactory) {
3562
3519
  isResponsibleForPrompt: isResponsibleForPrompt,
3563
3520
  };
3564
3521
  }
3565
- /**
3566
- * TODO: !!!! [🧠] Library precompilation and do not mix markdown and json promptbooks
3567
- */
3568
3522
 
3569
3523
  /**
3570
3524
  * Constructs Promptbook from remote Promptbase URL
3571
3525
 
3572
3526
  * @returns PromptbookLibrary
3573
3527
  */
3574
- function createPromptbookLibraryFromUrl(url, options) {
3528
+ function createLibraryFromUrl(url, options) {
3575
3529
  return __awaiter(this, void 0, void 0, function () {
3576
3530
  var _a, _b, isVerbose, _c, isLazyLoaded, library;
3577
3531
  var _this = this;
@@ -3579,7 +3533,7 @@ function createPromptbookLibraryFromUrl(url, options) {
3579
3533
  switch (_d.label) {
3580
3534
  case 0:
3581
3535
  _a = options || {}, _b = _a.isVerbose, isVerbose = _b === void 0 ? false : _b, _c = _a.isLazyLoaded, isLazyLoaded = _c === void 0 ? false : _c;
3582
- library = createPromptbookLibraryFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
3536
+ library = createLibraryFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
3583
3537
  return __generator(this, function (_a) {
3584
3538
  if (isVerbose) {
3585
3539
  console.info("Creating promptbook library from url ".concat(url.toString()));
@@ -3610,7 +3564,7 @@ function createPromptbookLibraryFromUrl(url, options) {
3610
3564
  * @param promptbookSources
3611
3565
  * @returns PromptbookLibrary
3612
3566
  */
3613
- function createPromptbookSublibrary(library, predicate) {
3567
+ function createSublibrary(library, predicate) {
3614
3568
  function listPromptbooks() {
3615
3569
  return __awaiter(this, void 0, void 0, function () {
3616
3570
  var promptbooks;
@@ -3680,6 +3634,28 @@ function createPromptbookSublibrary(library, predicate) {
3680
3634
  };
3681
3635
  }
3682
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
+
3683
3659
  /**
3684
3660
  * Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
3685
3661
  *
@@ -4114,5 +4090,5 @@ function executionReportJsonToString(executionReportJson, options) {
4114
4090
  * TODO: [🧠] Allow to filter out some parts of the report by options
4115
4091
  */
4116
4092
 
4117
- 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 };
4118
4094
  //# sourceMappingURL=index.es.js.map