@promptbook/cli 0.80.0-1 → 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 +2 -0
  2. package/esm/index.es.js +81 -56
  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 +1 -1
  23. package/umd/index.umd.js +81 -56
  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
@@ -308,6 +308,8 @@ Or you can install them separately:
308
308
  - **[@promptbook/documents](https://www.npmjs.com/package/@promptbook/documents)** - Read knowledge from documents like `.docx`, `.odt`,…
309
309
  - **[@promptbook/legacy-documents](https://www.npmjs.com/package/@promptbook/legacy-documents)** - Read knowledge from legacy documents like `.doc`, `.rtf`,…
310
310
  - **[@promptbook/website-crawler](https://www.npmjs.com/package/@promptbook/website-crawler)** - Crawl knowledge from the web
311
+ - **[@promptbook/editable](https://www.npmjs.com/package/@promptbook/editable)** - Editable book as native javascript object with imperative object API
312
+ - **[@promptbook/templates](https://www.npmjs.com/package/@promptbook/templates)** - Usefull templates and examples of books which can be used as a starting point
311
313
  - **[@promptbook/types](https://www.npmjs.com/package/@promptbook/types)** - Just typescript types used in the library
312
314
  - **[@promptbook/cli](https://www.npmjs.com/package/@promptbook/cli)** - Command line interface utilities for promptbooks
313
315
 
package/esm/index.es.js CHANGED
@@ -37,7 +37,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
37
37
  *
38
38
  * @see https://github.com/webgptorg/promptbook
39
39
  */
40
- var PROMPTBOOK_ENGINE_VERSION = '0.80.0-0';
40
+ var PROMPTBOOK_ENGINE_VERSION = '0.81.0-4';
41
41
  /**
42
42
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
43
43
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -488,6 +488,40 @@ function $provideFilesystemForNode(options) {
488
488
  * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
489
489
  */
490
490
 
491
+ /**
492
+ * Make error report URL for the given error
493
+ *
494
+ * @private !!!!!!
495
+ */
496
+ function getErrorReportUrl(error) {
497
+ var report = {
498
+ title: "\uD83D\uDC1C Error report from ".concat(NAME),
499
+ body: spaceTrim(function (block) { return "\n\n\n `".concat(error.name || 'Error', "` has occurred in the [").concat(NAME, "], please look into it @").concat(ADMIN_GITHUB_NAME, ".\n\n ```\n ").concat(block(error.message || '(no error message)'), "\n ```\n\n\n ## More info:\n\n - **Promptbook engine version:** ").concat(PROMPTBOOK_ENGINE_VERSION, "\n - **Book language version:** ").concat(BOOK_LANGUAGE_VERSION, "\n - **Time:** ").concat(new Date().toISOString(), "\n\n <details>\n <summary>Stack trace:</summary>\n\n ## Stack trace:\n\n ```stacktrace\n ").concat(block(error.stack || '(empty)'), "\n ```\n </details>\n\n "); }),
500
+ };
501
+ var reportUrl = new URL("https://github.com/webgptorg/promptbook/issues/new");
502
+ reportUrl.searchParams.set('labels', 'bug');
503
+ reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
504
+ reportUrl.searchParams.set('title', report.title);
505
+ reportUrl.searchParams.set('body', report.body);
506
+ return reportUrl;
507
+ }
508
+
509
+ /**
510
+ * This error type indicates that the error should not happen and its last check before crashing with some other error
511
+ *
512
+ * @public exported from `@promptbook/core`
513
+ */
514
+ var UnexpectedError = /** @class */ (function (_super) {
515
+ __extends(UnexpectedError, _super);
516
+ function UnexpectedError(message) {
517
+ var _this = _super.call(this, spaceTrim$1(function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the pipeline collection\n\n Please report issue:\n ").concat(block(getErrorReportUrl(new Error(message)).href), "\n\n Or contact us on ").concat(ADMIN_EMAIL, "\n\n "); })) || this;
518
+ _this.name = 'UnexpectedError';
519
+ Object.setPrototypeOf(_this, UnexpectedError.prototype);
520
+ return _this;
521
+ }
522
+ return UnexpectedError;
523
+ }(Error));
524
+
491
525
  /**
492
526
  * Orders JSON object by keys
493
527
  *
@@ -538,40 +572,6 @@ function $deepFreeze(objectValue) {
538
572
  * TODO: [🧠] Is there a way how to meaningfully test this utility
539
573
  */
540
574
 
541
- /**
542
- * Make error report URL for the given error
543
- *
544
- * @private !!!!!!
545
- */
546
- function getErrorReportUrl(error) {
547
- var report = {
548
- title: "\uD83D\uDC1C Error report from ".concat(NAME),
549
- body: spaceTrim(function (block) { return "\n\n\n `".concat(error.name || 'Error', "` has occurred in the [").concat(NAME, "], please look into it @").concat(ADMIN_GITHUB_NAME, ".\n\n ```\n ").concat(block(error.message || '(no error message)'), "\n ```\n\n\n ## More info:\n\n - **Promptbook engine version:** ").concat(PROMPTBOOK_ENGINE_VERSION, "\n - **Book language version:** ").concat(BOOK_LANGUAGE_VERSION, "\n - **Time:** ").concat(new Date().toISOString(), "\n\n <details>\n <summary>Stack trace:</summary>\n\n ## Stack trace:\n\n ```stacktrace\n ").concat(block(error.stack || '(empty)'), "\n ```\n </details>\n\n "); }),
550
- };
551
- var reportUrl = new URL("https://github.com/webgptorg/promptbook/issues/new");
552
- reportUrl.searchParams.set('labels', 'bug');
553
- reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
554
- reportUrl.searchParams.set('title', report.title);
555
- reportUrl.searchParams.set('body', report.body);
556
- return reportUrl;
557
- }
558
-
559
- /**
560
- * This error type indicates that the error should not happen and its last check before crashing with some other error
561
- *
562
- * @public exported from `@promptbook/core`
563
- */
564
- var UnexpectedError = /** @class */ (function (_super) {
565
- __extends(UnexpectedError, _super);
566
- function UnexpectedError(message) {
567
- var _this = _super.call(this, spaceTrim$1(function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the pipeline collection\n\n Please report issue:\n ").concat(block(getErrorReportUrl(new Error(message)).href), "\n\n Or contact us on ").concat(ADMIN_EMAIL, "\n\n "); })) || this;
568
- _this.name = 'UnexpectedError';
569
- Object.setPrototypeOf(_this, UnexpectedError.prototype);
570
- return _this;
571
- }
572
- return UnexpectedError;
573
- }(Error));
574
-
575
575
  /**
576
576
  * Checks if the value is [🚉] serializable as JSON
577
577
  * If not, throws an UnexpectedError with a rich error message and tracking
@@ -854,7 +854,7 @@ function isSerializableAsJson(value) {
854
854
  * Note: [0] It can be used for more JSON types like whole collection of pipelines, single knowledge piece, etc.
855
855
  * Note: In contrast to JSON.stringify, this function ensures that **embedding index** is on single line
856
856
  *
857
- * @public exported from `@promptbook/core`
857
+ * @public exported from `@promptbook/editable`
858
858
  */
859
859
  function stringifyPipelineJson(pipeline) {
860
860
  if (!isSerializableAsJson(pipeline)) {
@@ -4590,7 +4590,7 @@ function arrayableToArray(input) {
4590
4590
  * @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
4591
4591
  * @public exported from `@promptbook/utils`
4592
4592
  */
4593
- function replaceParameters(template, parameters) {
4593
+ function templateParameters(template, parameters) {
4594
4594
  var e_1, _a;
4595
4595
  try {
4596
4596
  for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
@@ -4616,7 +4616,7 @@ function replaceParameters(template, parameters) {
4616
4616
  var loopLimit = LOOP_LIMIT;
4617
4617
  var _loop_1 = function () {
4618
4618
  if (loopLimit-- < 0) {
4619
- throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`');
4619
+ throw new LimitReachedError('Loop limit reached during parameters replacement in `templateParameters`');
4620
4620
  }
4621
4621
  var precol = match.groups.precol;
4622
4622
  var parameterName = match.groups.parameterName;
@@ -4868,7 +4868,7 @@ function executeAttempts(options) {
4868
4868
  }
4869
4869
  return [3 /*break*/, 24];
4870
4870
  case 2:
4871
- $ongoingTaskResult.$resultString = replaceParameters(preparedContent, parameters);
4871
+ $ongoingTaskResult.$resultString = templateParameters(preparedContent, parameters);
4872
4872
  return [3 /*break*/, 25];
4873
4873
  case 3:
4874
4874
  modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (task.modelRequirements || {}));
@@ -4991,8 +4991,8 @@ function executeAttempts(options) {
4991
4991
  _j = $ongoingTaskResult;
4992
4992
  return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
4993
4993
  promptTitle: task.title,
4994
- promptMessage: replaceParameters(task.description || '', parameters),
4995
- defaultValue: replaceParameters(preparedContent, parameters),
4994
+ promptMessage: templateParameters(task.description || '', parameters),
4995
+ defaultValue: templateParameters(preparedContent, parameters),
4996
4996
  // TODO: [🧠] !! Figure out how to define placeholder in .book.md file
4997
4997
  placeholder: undefined,
4998
4998
  priority: priority,
@@ -5116,7 +5116,7 @@ function executeAttempts(options) {
5116
5116
  if (!isJokerAttempt &&
5117
5117
  task.taskType === 'PROMPT_TASK' &&
5118
5118
  $ongoingTaskResult.$prompt
5119
- // <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
5119
+ // <- Note: [2] When some expected parameter is not defined, error will occur in templateParameters
5120
5120
  // In that case we don’t want to make a report about it because it’s not a llm execution error
5121
5121
  ) {
5122
5122
  // TODO: [🧠] Maybe put other taskTypes into report
@@ -6180,6 +6180,30 @@ function getFileExtension(value) {
6180
6180
  return match ? match[1].toLowerCase() : null;
6181
6181
  }
6182
6182
 
6183
+ /**
6184
+ * The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
6185
+ *
6186
+ * @private as default `fetch` function used in Promptbook scrapers
6187
+ */
6188
+ var scraperFetch = function (url, init) { return __awaiter(void 0, void 0, void 0, function () {
6189
+ var error_1;
6190
+ return __generator(this, function (_a) {
6191
+ switch (_a.label) {
6192
+ case 0:
6193
+ _a.trys.push([0, 2, , 3]);
6194
+ return [4 /*yield*/, fetch(url, init)];
6195
+ case 1: return [2 /*return*/, _a.sent()];
6196
+ case 2:
6197
+ error_1 = _a.sent();
6198
+ if (!(error_1 instanceof Error)) {
6199
+ throw error_1;
6200
+ }
6201
+ throw new KnowledgeScrapeError(spaceTrim(function (block) { return "\n Can not fetch \"".concat(url, "\"\n\n Fetch error:\n ").concat(block(error_1.message), "\n\n "); }));
6202
+ case 3: return [2 /*return*/];
6203
+ }
6204
+ });
6205
+ }); };
6206
+
6183
6207
  /**
6184
6208
  * @@@
6185
6209
  *
@@ -6188,13 +6212,14 @@ function getFileExtension(value) {
6188
6212
  function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
6189
6213
  var _a;
6190
6214
  return __awaiter(this, void 0, void 0, function () {
6191
- var sourceContent, name, _b, _c, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
6192
- return __generator(this, function (_e) {
6193
- switch (_e.label) {
6215
+ var _b, fetch, sourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
6216
+ return __generator(this, function (_f) {
6217
+ switch (_f.label) {
6194
6218
  case 0:
6219
+ _b = tools.fetch, fetch = _b === void 0 ? scraperFetch : _b;
6195
6220
  sourceContent = knowledgeSource.sourceContent;
6196
6221
  name = knowledgeSource.name;
6197
- _b = options || {}, _c = _b.rootDirname, rootDirname = _c === void 0 ? null : _c, _b.isVerbose;
6222
+ _c = options || {}, _d = _c.rootDirname, rootDirname = _d === void 0 ? null : _d, _c.isVerbose;
6198
6223
  if (!name) {
6199
6224
  name = sourceContentToName(sourceContent);
6200
6225
  }
@@ -6202,7 +6227,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
6202
6227
  url = sourceContent;
6203
6228
  return [4 /*yield*/, fetch(url)];
6204
6229
  case 1:
6205
- response_1 = _e.sent();
6230
+ response_1 = _f.sent();
6206
6231
  mimeType = ((_a = response_1.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
6207
6232
  return [2 /*return*/, {
6208
6233
  source: name,
@@ -6259,7 +6284,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
6259
6284
  mimeType = extensionToMimeType(fileExtension || '');
6260
6285
  return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
6261
6286
  case 3:
6262
- if (!(_e.sent())) {
6287
+ if (!(_f.sent())) {
6263
6288
  throw new NotFoundError(spaceTrim(function (block) { return "\n Can not make source handler for file which does not exist:\n\n File:\n ".concat(block(filename_1), "\n "); }));
6264
6289
  }
6265
6290
  // TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
@@ -13186,7 +13211,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
13186
13211
  throw new PipelineExecutionError('Use callChatModel only for CHAT variant');
13187
13212
  }
13188
13213
  modelName = modelRequirements.modelName || this.getDefaultChatModel().modelName;
13189
- rawPromptContent = replaceParameters(content, __assign(__assign({}, parameters), { modelName: modelName }));
13214
+ rawPromptContent = templateParameters(content, __assign(__assign({}, parameters), { modelName: modelName }));
13190
13215
  rawRequest = {
13191
13216
  model: modelRequirements.modelName || this.getDefaultChatModel().modelName,
13192
13217
  max_tokens: modelRequirements.maxTokens || 4096,
@@ -13992,7 +14017,7 @@ var AzureOpenAiExecutionTools = /** @class */ (function () {
13992
14017
  // <- TODO: [🈁] Use `seed` here AND/OR use is `isDeterministic` for entire execution tools
13993
14018
  // <- Note: [🧆]
13994
14019
  };
13995
- rawPromptContent = replaceParameters(content, __assign(__assign({}, parameters), { modelName: modelName }));
14020
+ rawPromptContent = templateParameters(content, __assign(__assign({}, parameters), { modelName: modelName }));
13996
14021
  messages = __spreadArray(__spreadArray([], __read((modelRequirements.systemMessage === undefined
13997
14022
  ? []
13998
14023
  : [
@@ -14107,7 +14132,7 @@ var AzureOpenAiExecutionTools = /** @class */ (function () {
14107
14132
  console.info(colors.bgWhite('content'), JSON.stringify(content, null, 4));
14108
14133
  console.info(colors.bgWhite('parameters'), JSON.stringify(parameters, null, 4));
14109
14134
  }
14110
- rawPromptContent = replaceParameters(content, __assign(__assign({}, parameters), { modelName: modelName }));
14135
+ rawPromptContent = templateParameters(content, __assign(__assign({}, parameters), { modelName: modelName }));
14111
14136
  rawRequest = [
14112
14137
  modelName,
14113
14138
  [rawPromptContent],
@@ -14375,7 +14400,7 @@ function createExecutionToolsFromVercelProvider(options) {
14375
14400
  return [4 /*yield*/, vercelProvider.chat(modelName, __assign({ user: (userId === null || userId === void 0 ? void 0 : userId.toString()) || undefined }, additionalChatSettings))];
14376
14401
  case 1:
14377
14402
  model = _b.sent();
14378
- rawPromptContent = replaceParameters(content, __assign(__assign({}, parameters), { modelName: modelName }));
14403
+ rawPromptContent = templateParameters(content, __assign(__assign({}, parameters), { modelName: modelName }));
14379
14404
  rawRequest = {
14380
14405
  // <- TODO: [☂]
14381
14406
  inputFormat: 'messages',
@@ -14772,7 +14797,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
14772
14797
  type: 'json_object',
14773
14798
  };
14774
14799
  }
14775
- rawPromptContent = replaceParameters(content, __assign(__assign({}, parameters), { modelName: modelName }));
14800
+ rawPromptContent = templateParameters(content, __assign(__assign({}, parameters), { modelName: modelName }));
14776
14801
  rawRequest = __assign(__assign({}, modelSettings), { messages: __spreadArray(__spreadArray([], __read((modelRequirements.systemMessage === undefined
14777
14802
  ? []
14778
14803
  : [
@@ -14868,7 +14893,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
14868
14893
  // <- TODO: [🈁] Use `seed` here AND/OR use is `isDeterministic` for entire execution tools
14869
14894
  // <- Note: [🧆]
14870
14895
  };
14871
- rawPromptContent = replaceParameters(content, __assign(__assign({}, parameters), { modelName: modelName }));
14896
+ rawPromptContent = templateParameters(content, __assign(__assign({}, parameters), { modelName: modelName }));
14872
14897
  rawRequest = __assign(__assign({}, modelSettings), { prompt: rawPromptContent, user: (_a = this.options.userId) === null || _a === void 0 ? void 0 : _a.toString() });
14873
14898
  start = $getCurrentDate();
14874
14899
  if (this.options.isVerbose) {
@@ -14940,7 +14965,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
14940
14965
  throw new PipelineExecutionError('Use embed only for EMBEDDING variant');
14941
14966
  }
14942
14967
  modelName = modelRequirements.modelName || this.getDefaultEmbeddingModel().modelName;
14943
- rawPromptContent = replaceParameters(content, __assign(__assign({}, parameters), { modelName: modelName }));
14968
+ rawPromptContent = templateParameters(content, __assign(__assign({}, parameters), { modelName: modelName }));
14944
14969
  rawRequest = {
14945
14970
  input: rawPromptContent,
14946
14971
  model: modelName,
@@ -15110,7 +15135,7 @@ var OpenAiAssistantExecutionTools = /** @class */ (function (_super) {
15110
15135
  }
15111
15136
  finally { if (e_1) throw e_1.error; }
15112
15137
  }
15113
- rawPromptContent = replaceParameters(content, __assign(__assign({}, parameters), { modelName: 'assistant' }));
15138
+ rawPromptContent = templateParameters(content, __assign(__assign({}, parameters), { modelName: 'assistant' }));
15114
15139
  rawRequest = {
15115
15140
  // TODO: [👨‍👨‍👧‍👧] ...modelSettings,
15116
15141
  // TODO: [👨‍👨‍👧‍👧][🧠] What about system message for assistants, does it make sence - combination of OpenAI assistants with Promptbook Personas