@promptbook/documents 0.80.0 → 0.81.0-5

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 (28) hide show
  1. package/README.md +6 -0
  2. package/esm/index.es.js +38 -13
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/core.index.d.ts +0 -6
  5. package/esm/typings/src/_packages/editable.index.d.ts +10 -0
  6. package/esm/typings/src/_packages/templates.index.d.ts +4 -0
  7. package/esm/typings/src/_packages/types.index.d.ts +4 -0
  8. package/esm/typings/src/_packages/utils.index.d.ts +2 -2
  9. package/esm/typings/src/execution/ExecutionTools.d.ts +7 -0
  10. package/esm/typings/src/execution/PromptbookFetch.d.ts +5 -0
  11. package/esm/typings/src/execution/PromptbookFetch.test-type.d.ts +5 -0
  12. package/esm/typings/src/expectations/drafts/isDomainNameFree.d.ts +2 -1
  13. package/esm/typings/src/expectations/drafts/isGithubNameFree.d.ts +2 -1
  14. package/esm/typings/src/scrapers/_common/utils/makeKnowledgeSourceHandler.d.ts +1 -1
  15. package/esm/typings/src/scrapers/_common/utils/scraperFetch.d.ts +7 -0
  16. package/esm/typings/src/utils/editable/types/PipelineEditableSerialized.d.ts +42 -0
  17. package/esm/typings/src/{conversion → utils/editable}/utils/removePipelineCommand.d.ts +3 -3
  18. package/esm/typings/src/{conversion → utils/editable}/utils/renamePipelineParameter.d.ts +3 -3
  19. package/esm/typings/src/{conversion → utils/editable}/utils/stringifyPipelineJson.d.ts +2 -2
  20. package/esm/typings/src/utils/getBookTemplate.d.ts +12 -0
  21. package/esm/typings/src/utils/parameters/{replaceParameters.d.ts → templateParameters.d.ts} +1 -1
  22. package/package.json +2 -2
  23. package/umd/index.umd.js +38 -13
  24. package/umd/index.umd.js.map +1 -1
  25. /package/esm/typings/src/{conversion → utils/editable}/utils/removePipelineCommand.test.d.ts +0 -0
  26. /package/esm/typings/src/{conversion → utils/editable}/utils/renamePipelineParameter.test.d.ts +0 -0
  27. /package/esm/typings/src/{conversion → utils/editable}/utils/stringifyPipelineJson.test.d.ts +0 -0
  28. /package/esm/typings/src/utils/parameters/{replaceParameters.test.d.ts → templateParameters.test.d.ts} +0 -0
package/README.md CHANGED
@@ -23,6 +23,10 @@
23
23
 
24
24
 
25
25
 
26
+ <blockquote style="color: #ff8811">
27
+ <b>⚠ Warning:</b> This is a pre-release version of the library. It is not yet ready for production use. Please look at <a href="https://www.npmjs.com/package/@promptbook/core?activeTab=versions">latest stable release</a>.
28
+ </blockquote>
29
+
26
30
  ## 📦 Package `@promptbook/documents`
27
31
 
28
32
  - Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
@@ -250,6 +254,8 @@ Or you can install them separately:
250
254
  - **[@promptbook/documents](https://www.npmjs.com/package/@promptbook/documents)** - Read knowledge from documents like `.docx`, `.odt`,…
251
255
  - **[@promptbook/legacy-documents](https://www.npmjs.com/package/@promptbook/legacy-documents)** - Read knowledge from legacy documents like `.doc`, `.rtf`,…
252
256
  - **[@promptbook/website-crawler](https://www.npmjs.com/package/@promptbook/website-crawler)** - Crawl knowledge from the web
257
+ - **[@promptbook/editable](https://www.npmjs.com/package/@promptbook/editable)** - Editable book as native javascript object with imperative object API
258
+ - **[@promptbook/templates](https://www.npmjs.com/package/@promptbook/templates)** - Usefull templates and examples of books which can be used as a starting point
253
259
  - **[@promptbook/types](https://www.npmjs.com/package/@promptbook/types)** - Just typescript types used in the library
254
260
  - **[@promptbook/cli](https://www.npmjs.com/package/@promptbook/cli)** - Command line interface utilities for promptbooks
255
261
 
package/esm/index.es.js CHANGED
@@ -23,7 +23,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
23
23
  *
24
24
  * @see https://github.com/webgptorg/promptbook
25
25
  */
26
- var PROMPTBOOK_ENGINE_VERSION = '0.80.0-1';
26
+ var PROMPTBOOK_ENGINE_VERSION = '0.81.0-4';
27
27
  /**
28
28
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
29
29
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -3499,6 +3499,30 @@ function extensionToMimeType(value) {
3499
3499
  return lookup(value) || 'application/octet-stream';
3500
3500
  }
3501
3501
 
3502
+ /**
3503
+ * The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
3504
+ *
3505
+ * @private as default `fetch` function used in Promptbook scrapers
3506
+ */
3507
+ var scraperFetch = function (url, init) { return __awaiter(void 0, void 0, void 0, function () {
3508
+ var error_1;
3509
+ return __generator(this, function (_a) {
3510
+ switch (_a.label) {
3511
+ case 0:
3512
+ _a.trys.push([0, 2, , 3]);
3513
+ return [4 /*yield*/, fetch(url, init)];
3514
+ case 1: return [2 /*return*/, _a.sent()];
3515
+ case 2:
3516
+ error_1 = _a.sent();
3517
+ if (!(error_1 instanceof Error)) {
3518
+ throw error_1;
3519
+ }
3520
+ throw new KnowledgeScrapeError(spaceTrim$1(function (block) { return "\n Can not fetch \"".concat(url, "\"\n\n Fetch error:\n ").concat(block(error_1.message), "\n\n "); }));
3521
+ case 3: return [2 /*return*/];
3522
+ }
3523
+ });
3524
+ }); };
3525
+
3502
3526
  /**
3503
3527
  * @@@
3504
3528
  *
@@ -3507,13 +3531,14 @@ function extensionToMimeType(value) {
3507
3531
  function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
3508
3532
  var _a;
3509
3533
  return __awaiter(this, void 0, void 0, function () {
3510
- var sourceContent, name, _b, _c, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
3511
- return __generator(this, function (_e) {
3512
- switch (_e.label) {
3534
+ var _b, fetch, sourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
3535
+ return __generator(this, function (_f) {
3536
+ switch (_f.label) {
3513
3537
  case 0:
3538
+ _b = tools.fetch, fetch = _b === void 0 ? scraperFetch : _b;
3514
3539
  sourceContent = knowledgeSource.sourceContent;
3515
3540
  name = knowledgeSource.name;
3516
- _b = options || {}, _c = _b.rootDirname, rootDirname = _c === void 0 ? null : _c, _b.isVerbose;
3541
+ _c = options || {}, _d = _c.rootDirname, rootDirname = _d === void 0 ? null : _d, _c.isVerbose;
3517
3542
  if (!name) {
3518
3543
  name = sourceContentToName(sourceContent);
3519
3544
  }
@@ -3521,7 +3546,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
3521
3546
  url = sourceContent;
3522
3547
  return [4 /*yield*/, fetch(url)];
3523
3548
  case 1:
3524
- response_1 = _e.sent();
3549
+ response_1 = _f.sent();
3525
3550
  mimeType = ((_a = response_1.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
3526
3551
  return [2 /*return*/, {
3527
3552
  source: name,
@@ -3578,7 +3603,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
3578
3603
  mimeType = extensionToMimeType(fileExtension || '');
3579
3604
  return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
3580
3605
  case 3:
3581
- if (!(_e.sent())) {
3606
+ if (!(_f.sent())) {
3582
3607
  throw new NotFoundError(spaceTrim$1(function (block) { return "\n Can not make source handler for file which does not exist:\n\n File:\n ".concat(block(filename_1), "\n "); }));
3583
3608
  }
3584
3609
  // TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
@@ -4615,7 +4640,7 @@ function extractJsonBlock(markdown) {
4615
4640
  * @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
4616
4641
  * @public exported from `@promptbook/utils`
4617
4642
  */
4618
- function replaceParameters(template, parameters) {
4643
+ function templateParameters(template, parameters) {
4619
4644
  var e_1, _a;
4620
4645
  try {
4621
4646
  for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
@@ -4641,7 +4666,7 @@ function replaceParameters(template, parameters) {
4641
4666
  var loopLimit = LOOP_LIMIT;
4642
4667
  var _loop_1 = function () {
4643
4668
  if (loopLimit-- < 0) {
4644
- throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`');
4669
+ throw new LimitReachedError('Loop limit reached during parameters replacement in `templateParameters`');
4645
4670
  }
4646
4671
  var precol = match.groups.precol;
4647
4672
  var parameterName = match.groups.parameterName;
@@ -4893,7 +4918,7 @@ function executeAttempts(options) {
4893
4918
  }
4894
4919
  return [3 /*break*/, 24];
4895
4920
  case 2:
4896
- $ongoingTaskResult.$resultString = replaceParameters(preparedContent, parameters);
4921
+ $ongoingTaskResult.$resultString = templateParameters(preparedContent, parameters);
4897
4922
  return [3 /*break*/, 25];
4898
4923
  case 3:
4899
4924
  modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (task.modelRequirements || {}));
@@ -5016,8 +5041,8 @@ function executeAttempts(options) {
5016
5041
  _j = $ongoingTaskResult;
5017
5042
  return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
5018
5043
  promptTitle: task.title,
5019
- promptMessage: replaceParameters(task.description || '', parameters),
5020
- defaultValue: replaceParameters(preparedContent, parameters),
5044
+ promptMessage: templateParameters(task.description || '', parameters),
5045
+ defaultValue: templateParameters(preparedContent, parameters),
5021
5046
  // TODO: [🧠] !! Figure out how to define placeholder in .book.md file
5022
5047
  placeholder: undefined,
5023
5048
  priority: priority,
@@ -5141,7 +5166,7 @@ function executeAttempts(options) {
5141
5166
  if (!isJokerAttempt &&
5142
5167
  task.taskType === 'PROMPT_TASK' &&
5143
5168
  $ongoingTaskResult.$prompt
5144
- // <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
5169
+ // <- Note: [2] When some expected parameter is not defined, error will occur in templateParameters
5145
5170
  // In that case we don’t want to make a report about it because it’s not a llm execution error
5146
5171
  ) {
5147
5172
  // TODO: [🧠] Maybe put other taskTypes into report