@promptbook/pdf 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/pdf`
27
31
 
28
32
  - Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
@@ -249,6 +253,8 @@ Or you can install them separately:
249
253
  - **[@promptbook/documents](https://www.npmjs.com/package/@promptbook/documents)** - Read knowledge from documents like `.docx`, `.odt`,…
250
254
  - **[@promptbook/legacy-documents](https://www.npmjs.com/package/@promptbook/legacy-documents)** - Read knowledge from legacy documents like `.doc`, `.rtf`,…
251
255
  - **[@promptbook/website-crawler](https://www.npmjs.com/package/@promptbook/website-crawler)** - Crawl knowledge from the web
256
+ - **[@promptbook/editable](https://www.npmjs.com/package/@promptbook/editable)** - Editable book as native javascript object with imperative object API
257
+ - **[@promptbook/templates](https://www.npmjs.com/package/@promptbook/templates)** - Usefull templates and examples of books which can be used as a starting point
252
258
  - **[@promptbook/types](https://www.npmjs.com/package/@promptbook/types)** - Just typescript types used in the library
253
259
  - **[@promptbook/cli](https://www.npmjs.com/package/@promptbook/cli)** - Command line interface utilities for promptbooks
254
260
 
package/esm/index.es.js CHANGED
@@ -20,7 +20,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
20
20
  *
21
21
  * @see https://github.com/webgptorg/promptbook
22
22
  */
23
- var PROMPTBOOK_ENGINE_VERSION = '0.80.0-1';
23
+ var PROMPTBOOK_ENGINE_VERSION = '0.81.0-4';
24
24
  /**
25
25
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
26
26
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -3218,6 +3218,30 @@ function isValidFilePath(filename) {
3218
3218
  return false;
3219
3219
  }
3220
3220
 
3221
+ /**
3222
+ * The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
3223
+ *
3224
+ * @private as default `fetch` function used in Promptbook scrapers
3225
+ */
3226
+ var scraperFetch = function (url, init) { return __awaiter(void 0, void 0, void 0, function () {
3227
+ var error_1;
3228
+ return __generator(this, function (_a) {
3229
+ switch (_a.label) {
3230
+ case 0:
3231
+ _a.trys.push([0, 2, , 3]);
3232
+ return [4 /*yield*/, fetch(url, init)];
3233
+ case 1: return [2 /*return*/, _a.sent()];
3234
+ case 2:
3235
+ error_1 = _a.sent();
3236
+ if (!(error_1 instanceof Error)) {
3237
+ throw error_1;
3238
+ }
3239
+ 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 "); }));
3240
+ case 3: return [2 /*return*/];
3241
+ }
3242
+ });
3243
+ }); };
3244
+
3221
3245
  /**
3222
3246
  * @@@
3223
3247
  *
@@ -3226,13 +3250,14 @@ function isValidFilePath(filename) {
3226
3250
  function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
3227
3251
  var _a;
3228
3252
  return __awaiter(this, void 0, void 0, function () {
3229
- var sourceContent, name, _b, _c, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
3230
- return __generator(this, function (_e) {
3231
- switch (_e.label) {
3253
+ var _b, fetch, sourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
3254
+ return __generator(this, function (_f) {
3255
+ switch (_f.label) {
3232
3256
  case 0:
3257
+ _b = tools.fetch, fetch = _b === void 0 ? scraperFetch : _b;
3233
3258
  sourceContent = knowledgeSource.sourceContent;
3234
3259
  name = knowledgeSource.name;
3235
- _b = options || {}, _c = _b.rootDirname, rootDirname = _c === void 0 ? null : _c, _b.isVerbose;
3260
+ _c = options || {}, _d = _c.rootDirname, rootDirname = _d === void 0 ? null : _d, _c.isVerbose;
3236
3261
  if (!name) {
3237
3262
  name = sourceContentToName(sourceContent);
3238
3263
  }
@@ -3240,7 +3265,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
3240
3265
  url = sourceContent;
3241
3266
  return [4 /*yield*/, fetch(url)];
3242
3267
  case 1:
3243
- response_1 = _e.sent();
3268
+ response_1 = _f.sent();
3244
3269
  mimeType = ((_a = response_1.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
3245
3270
  return [2 /*return*/, {
3246
3271
  source: name,
@@ -3297,7 +3322,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
3297
3322
  mimeType = extensionToMimeType(fileExtension || '');
3298
3323
  return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
3299
3324
  case 3:
3300
- if (!(_e.sent())) {
3325
+ if (!(_f.sent())) {
3301
3326
  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 "); }));
3302
3327
  }
3303
3328
  // TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
@@ -4334,7 +4359,7 @@ function extractJsonBlock(markdown) {
4334
4359
  * @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
4335
4360
  * @public exported from `@promptbook/utils`
4336
4361
  */
4337
- function replaceParameters(template, parameters) {
4362
+ function templateParameters(template, parameters) {
4338
4363
  var e_1, _a;
4339
4364
  try {
4340
4365
  for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
@@ -4360,7 +4385,7 @@ function replaceParameters(template, parameters) {
4360
4385
  var loopLimit = LOOP_LIMIT;
4361
4386
  var _loop_1 = function () {
4362
4387
  if (loopLimit-- < 0) {
4363
- throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`');
4388
+ throw new LimitReachedError('Loop limit reached during parameters replacement in `templateParameters`');
4364
4389
  }
4365
4390
  var precol = match.groups.precol;
4366
4391
  var parameterName = match.groups.parameterName;
@@ -4612,7 +4637,7 @@ function executeAttempts(options) {
4612
4637
  }
4613
4638
  return [3 /*break*/, 24];
4614
4639
  case 2:
4615
- $ongoingTaskResult.$resultString = replaceParameters(preparedContent, parameters);
4640
+ $ongoingTaskResult.$resultString = templateParameters(preparedContent, parameters);
4616
4641
  return [3 /*break*/, 25];
4617
4642
  case 3:
4618
4643
  modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (task.modelRequirements || {}));
@@ -4735,8 +4760,8 @@ function executeAttempts(options) {
4735
4760
  _j = $ongoingTaskResult;
4736
4761
  return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
4737
4762
  promptTitle: task.title,
4738
- promptMessage: replaceParameters(task.description || '', parameters),
4739
- defaultValue: replaceParameters(preparedContent, parameters),
4763
+ promptMessage: templateParameters(task.description || '', parameters),
4764
+ defaultValue: templateParameters(preparedContent, parameters),
4740
4765
  // TODO: [🧠] !! Figure out how to define placeholder in .book.md file
4741
4766
  placeholder: undefined,
4742
4767
  priority: priority,
@@ -4860,7 +4885,7 @@ function executeAttempts(options) {
4860
4885
  if (!isJokerAttempt &&
4861
4886
  task.taskType === 'PROMPT_TASK' &&
4862
4887
  $ongoingTaskResult.$prompt
4863
- // <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
4888
+ // <- Note: [2] When some expected parameter is not defined, error will occur in templateParameters
4864
4889
  // In that case we don’t want to make a report about it because it’s not a llm execution error
4865
4890
  ) {
4866
4891
  // TODO: [🧠] Maybe put other taskTypes into report