@promptbook/cli 0.59.0-25 → 0.59.0-26

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.
package/umd/index.umd.js CHANGED
@@ -147,7 +147,7 @@
147
147
  /**
148
148
  * The version of the Promptbook library
149
149
  */
150
- var PROMPTBOOK_VERSION = '0.59.0-24';
150
+ var PROMPTBOOK_VERSION = '0.59.0-25';
151
151
 
152
152
  /**
153
153
  * Initializes testing `hello` command for Promptbook CLI utilities
@@ -188,61 +188,6 @@
188
188
  */
189
189
  var PROMPTBOOK_MAKED_BASE_FILENAME = "promptbook-library";
190
190
 
191
- /**
192
- * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
193
- */
194
- var PromptbookSyntaxError = /** @class */ (function (_super) {
195
- __extends(PromptbookSyntaxError, _super);
196
- function PromptbookSyntaxError(message) {
197
- var _this = _super.call(this, message) || this;
198
- _this.name = 'PromptbookSyntaxError';
199
- Object.setPrototypeOf(_this, PromptbookSyntaxError.prototype);
200
- return _this;
201
- }
202
- return PromptbookSyntaxError;
203
- }(Error));
204
-
205
- var promptbookLibrary = [{title:"Prepare Knowledge from Markdown",promptbookUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.59.0-24",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:[]}];
206
-
207
- /**
208
- * This error indicates errors during the execution of the promptbook
209
- */
210
- var PromptbookExecutionError = /** @class */ (function (_super) {
211
- __extends(PromptbookExecutionError, _super);
212
- function PromptbookExecutionError(message) {
213
- var _this = _super.call(this, message) || this;
214
- _this.name = 'PromptbookExecutionError';
215
- Object.setPrototypeOf(_this, PromptbookExecutionError.prototype);
216
- return _this;
217
- }
218
- return PromptbookExecutionError;
219
- }(Error));
220
-
221
- /**
222
- * Asserts that the execution of a promptnook is successful
223
- *
224
- * @param executionResult - The partial result of the promptnook execution
225
- * @throws {PromptbookExecutionError} If the execution is not successful or if multiple errors occurred
226
- */
227
- function assertsExecutionSuccessful(executionResult) {
228
- var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors;
229
- if (isSuccessful === true) {
230
- return;
231
- }
232
- if (errors.length === 0) {
233
- throw new PromptbookExecutionError("Promptnook Execution failed because of unknown reason");
234
- }
235
- else if (errors.length === 1) {
236
- throw errors[0];
237
- }
238
- else {
239
- throw new PromptbookExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Multiple errors occurred during promptnook execution\n\n ".concat(block(errors.map(function (error) { return '- ' + error.message; }).join('\n')), "\n "); }));
240
- }
241
- }
242
- /**
243
- * TODO: [🧠] Can this return type be better typed than void
244
- */
245
-
246
191
  /**
247
192
  * This error indicates that the promptbook object has valid syntax but contains logical errors (like circular dependencies)
248
193
  */
@@ -257,6 +202,20 @@
257
202
  return PromptbookLogicError;
258
203
  }(Error));
259
204
 
205
+ /**
206
+ * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
207
+ */
208
+ var PromptbookSyntaxError = /** @class */ (function (_super) {
209
+ __extends(PromptbookSyntaxError, _super);
210
+ function PromptbookSyntaxError(message) {
211
+ var _this = _super.call(this, message) || this;
212
+ _this.name = 'PromptbookSyntaxError';
213
+ Object.setPrototypeOf(_this, PromptbookSyntaxError.prototype);
214
+ return _this;
215
+ }
216
+ return PromptbookSyntaxError;
217
+ }(Error));
218
+
260
219
  /**
261
220
  * This error type indicates that the error should not happen and its last check before crashing with some other error
262
221
  */
@@ -310,7 +269,7 @@
310
269
  * @returns the same promptbook if it is logically valid
311
270
  * @throws {PromptbookLogicError} on logical error in the promptbook
312
271
  */
313
- function validatePromptbookJson(promptbook) {
272
+ function validatePromptbook(promptbook) {
314
273
  // TODO: [🧠] Maybe test if promptbook is a promise and make specific error case for that
315
274
  var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
316
275
  if (promptbook.promptbookUrl !== undefined) {
@@ -374,8 +333,7 @@
374
333
  throw new PromptbookLogicError("Parameter {".concat(template.resultingParameterName, "} is defined multiple times"));
375
334
  }
376
335
  definedParameters.add(template.resultingParameterName);
377
- if (template.executionType === 'PROMPT_TEMPLATE' &&
378
- (template.modelRequirements.modelVariant === undefined)) {
336
+ if (template.executionType === 'PROMPT_TEMPLATE' && template.modelRequirements.modelVariant === undefined) {
379
337
  throw new PromptbookLogicError(spaceTrim.spaceTrim("\n\n You must specify MODEL VARIANT in the prompt template \"".concat(template.title, "\"\n\n For example:\n - MODEL VARIANT Chat\n - MODEL NAME `gpt-4-1106-preview`\n\n ")));
380
338
  }
381
339
  if (template.jokers && template.jokers.length > 0) {
@@ -445,7 +403,7 @@
445
403
  var loopLimit = LOOP_LIMIT;
446
404
  var _loop_2 = function () {
447
405
  if (loopLimit-- < 0) {
448
- throw new UnexpectedError('Loop limit reached during detection of circular dependencies in `validatePromptbookJson`');
406
+ throw new UnexpectedError('Loop limit reached during detection of circular dependencies in `validatePromptbook`');
449
407
  }
450
408
  var currentlyResovedTemplates = unresovedTemplates.filter(function (template) {
451
409
  return template.dependentParameterNames.every(function (name) { return resovedParameters.includes(name); });
@@ -480,7 +438,48 @@
480
438
  * > * It checks:
481
439
  * > * - it has a valid structure
482
440
  * > * - ...
483
- * > ex port function validatePromptbookJson(promptbook: unknown): asserts promptbook is PromptbookJson {
441
+ * > ex port function validatePromptbook(promptbook: unknown): asserts promptbook is PromptbookJson {
442
+ */
443
+
444
+ var promptbookLibrary = [{title:"Prepare Knowledge from Markdown",promptbookUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.59.0-25",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:[]}];
445
+
446
+ /**
447
+ * This error indicates errors during the execution of the promptbook
448
+ */
449
+ var PromptbookExecutionError = /** @class */ (function (_super) {
450
+ __extends(PromptbookExecutionError, _super);
451
+ function PromptbookExecutionError(message) {
452
+ var _this = _super.call(this, message) || this;
453
+ _this.name = 'PromptbookExecutionError';
454
+ Object.setPrototypeOf(_this, PromptbookExecutionError.prototype);
455
+ return _this;
456
+ }
457
+ return PromptbookExecutionError;
458
+ }(Error));
459
+
460
+ /**
461
+ * Asserts that the execution of a promptnook is successful
462
+ *
463
+ * @param executionResult - The partial result of the promptnook execution
464
+ * @throws {PromptbookExecutionError} If the execution is not successful or if multiple errors occurred
465
+ */
466
+ function assertsExecutionSuccessful(executionResult) {
467
+ var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors;
468
+ if (isSuccessful === true) {
469
+ return;
470
+ }
471
+ if (errors.length === 0) {
472
+ throw new PromptbookExecutionError("Promptnook Execution failed because of unknown reason");
473
+ }
474
+ else if (errors.length === 1) {
475
+ throw errors[0];
476
+ }
477
+ else {
478
+ throw new PromptbookExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Multiple errors occurred during promptnook execution\n\n ".concat(block(errors.map(function (error) { return '- ' + error.message; }).join('\n')), "\n "); }));
479
+ }
480
+ }
481
+ /**
482
+ * TODO: [🧠] Can this return type be better typed than void
484
483
  */
485
484
 
486
485
  /**
@@ -1058,7 +1057,7 @@
1058
1057
  var _this = this;
1059
1058
  var promptbook = options.promptbook, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
1060
1059
  var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ? 3 : _b;
1061
- validatePromptbookJson(promptbook);
1060
+ validatePromptbook(promptbook);
1062
1061
  var promptbookExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
1063
1062
  function executeSingleTemplate(currentTemplate) {
1064
1063
  return __awaiter(this, void 0, void 0, function () {
@@ -1489,7 +1488,7 @@
1489
1488
  return template.dependentParameterNames.every(function (name) { return resovedParameters_1.includes(name); });
1490
1489
  });
1491
1490
  if (!(!currentTemplate && resolving_1.length === 0)) return [3 /*break*/, 1];
1492
- throw new UnexpectedError(spaceTrim.spaceTrim("\n Can not resolve some parameters\n\n Note: This should be catched during validatePromptbookJson\n "));
1491
+ throw new UnexpectedError(spaceTrim.spaceTrim("\n Can not resolve some parameters\n\n Note: This should be catched during validatePromptbook\n "));
1493
1492
  case 1:
1494
1493
  if (!!currentTemplate) return [3 /*break*/, 3];
1495
1494
  /* [5] */ return [4 /*yield*/, Promise.race(resolving_1)];
@@ -1876,7 +1875,7 @@
1876
1875
  if (promptbook.promptbookUrl === undefined) {
1877
1876
  throw new PromptbookReferenceError(spaceTrim.spaceTrim("\n Promptbook with name \"".concat(promptbook.title, "\" does not have defined URL\n\n Note: Promptbooks without URLs are called anonymous promptbooks\n They can be used as standalone promptbooks, but they cannot be referenced by other promptbooks\n And also they cannot be used in the promptbook library\n\n ")));
1878
1877
  }
1879
- validatePromptbookJson(promptbook);
1878
+ validatePromptbook(promptbook);
1880
1879
  // Note: [🦄]
1881
1880
  if (this.library.has(promptbook.promptbookUrl) &&
1882
1881
  promptbookJsonToString(promptbook) !==
@@ -1941,11 +1940,7 @@
1941
1940
  for (var _i = 0; _i < arguments.length; _i++) {
1942
1941
  promptbooks[_i] = arguments[_i];
1943
1942
  }
1944
- return __awaiter(this, void 0, void 0, function () {
1945
- return __generator(this, function (_a) {
1946
- return [2 /*return*/, new (SimplePromptbookLibrary.bind.apply(SimplePromptbookLibrary, __spreadArray([void 0], __read(promptbooks), false)))()];
1947
- });
1948
- });
1943
+ return new (SimplePromptbookLibrary.bind.apply(SimplePromptbookLibrary, __spreadArray([void 0], __read(promptbooks), false)))();
1949
1944
  }
1950
1945
 
1951
1946
  /* tslint:disable */
@@ -2011,9 +2006,7 @@
2011
2006
  switch (_b.label) {
2012
2007
  case 0:
2013
2008
  content = options.content, llmTools = options.llmTools, _a = options.isVerbose, isVerbose = _a === void 0 ? false : _a;
2014
- return [4 /*yield*/, createLibraryFromJson.apply(void 0, __spreadArray([], __read(promptbookLibrary), false))];
2015
- case 1:
2016
- library = _b.sent();
2009
+ library = createLibraryFromJson.apply(void 0, __spreadArray([], __read(promptbookLibrary), false));
2017
2010
  promptbook = library.getPromptbookByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md');
2018
2011
  executor = createPromptbookExecutor({
2019
2012
  promptbook: promptbook,
@@ -2025,7 +2018,7 @@
2025
2018
  },
2026
2019
  });
2027
2020
  return [4 /*yield*/, executor({ content: content })];
2028
- case 2:
2021
+ case 1:
2029
2022
  result = _b.sent();
2030
2023
  assertsExecutionSuccessful(result);
2031
2024
  outputParameters = result.outputParameters;
@@ -2064,7 +2057,7 @@
2064
2057
  }];
2065
2058
  });
2066
2059
  }); }))];
2067
- case 3:
2060
+ case 2:
2068
2061
  knowledge = _b.sent();
2069
2062
  return [2 /*return*/, knowledge];
2070
2063
  }
@@ -3234,9 +3227,7 @@
3234
3227
  return [4 /*yield*/, promptbookSourcesPromiseOrFactory];
3235
3228
  case 1:
3236
3229
  promptbookSources = _a.sent();
3237
- return [4 /*yield*/, createLibraryFromJson.apply(void 0, __spreadArray([], __read(promptbookSources), false))];
3238
- case 2:
3239
- library = _a.sent();
3230
+ library = createLibraryFromJson.apply(void 0, __spreadArray([], __read(promptbookSources), false));
3240
3231
  return [2 /*return*/];
3241
3232
  }
3242
3233
  });
@@ -3380,7 +3371,7 @@
3380
3371
  if (!isCrashOnError) {
3381
3372
  // Note: Validate promptbook to check if it is logically correct to not crash on invalid promptbooks
3382
3373
  // But be handled in current try-catch block
3383
- validatePromptbookJson(promptbook);
3374
+ validatePromptbook(promptbook);
3384
3375
  }
3385
3376
  // Note: [🦄] Promptbook with same url uniqueness will be checked automatically in SimplePromptbookLibrary
3386
3377
  promptbooks.push(promptbook);
@@ -3545,21 +3536,84 @@
3545
3536
  helloCommand.action(function (path$1, _a) {
3546
3537
  var projectName = _a.projectName, format = _a.format, validation = _a.validation;
3547
3538
  return __awaiter(_this, void 0, void 0, function () {
3548
- var library, libraryJson, libraryJsonString, saveFile;
3539
+ var formats, validations, library, validations_1, validations_1_1, validation_1, _b, _c, promptbookUrl, promptbook, e_1_1, e_2_1, libraryJson, libraryJsonString, saveFile;
3540
+ var e_2, _d, e_1, _e;
3549
3541
  var _this = this;
3550
- return __generator(this, function (_b) {
3551
- switch (_b.label) {
3542
+ return __generator(this, function (_f) {
3543
+ switch (_f.label) {
3552
3544
  case 0:
3553
3545
  console.info('!!!', { projectName: projectName, path: path$1, format: format, validation: validation });
3546
+ formats = (format || '')
3547
+ .split(',')
3548
+ .map(function (_) { return _.trim(); })
3549
+ .filter(function (_) { return _ !== ''; });
3550
+ validations = (validation || '')
3551
+ .split(',')
3552
+ .map(function (_) { return _.trim(); })
3553
+ .filter(function (_) { return _ !== ''; });
3554
3554
  return [4 /*yield*/, createLibraryFromDirectory(path$1, {
3555
3555
  isVerbose: true,
3556
3556
  isRecursive: true,
3557
3557
  })];
3558
3558
  case 1:
3559
- library = _b.sent();
3560
- return [4 /*yield*/, libraryToJson(library)];
3559
+ library = _f.sent();
3560
+ _f.label = 2;
3561
3561
  case 2:
3562
- libraryJson = _b.sent();
3562
+ _f.trys.push([2, 14, 15, 16]);
3563
+ validations_1 = __values(validations), validations_1_1 = validations_1.next();
3564
+ _f.label = 3;
3565
+ case 3:
3566
+ if (!!validations_1_1.done) return [3 /*break*/, 13];
3567
+ validation_1 = validations_1_1.value;
3568
+ _f.label = 4;
3569
+ case 4:
3570
+ _f.trys.push([4, 10, 11, 12]);
3571
+ e_1 = void 0;
3572
+ return [4 /*yield*/, library.listPromptbooks()];
3573
+ case 5:
3574
+ _b = (__values.apply(void 0, [_f.sent()])), _c = _b.next();
3575
+ _f.label = 6;
3576
+ case 6:
3577
+ if (!!_c.done) return [3 /*break*/, 9];
3578
+ promptbookUrl = _c.value;
3579
+ return [4 /*yield*/, library.getPromptbookByUrl(promptbookUrl)];
3580
+ case 7:
3581
+ promptbook = _f.sent();
3582
+ if (validation_1 === 'logic') {
3583
+ validatePromptbook(promptbook);
3584
+ }
3585
+ _f.label = 8;
3586
+ case 8:
3587
+ _c = _b.next();
3588
+ return [3 /*break*/, 6];
3589
+ case 9: return [3 /*break*/, 12];
3590
+ case 10:
3591
+ e_1_1 = _f.sent();
3592
+ e_1 = { error: e_1_1 };
3593
+ return [3 /*break*/, 12];
3594
+ case 11:
3595
+ try {
3596
+ if (_c && !_c.done && (_e = _b.return)) _e.call(_b);
3597
+ }
3598
+ finally { if (e_1) throw e_1.error; }
3599
+ return [7 /*endfinally*/];
3600
+ case 12:
3601
+ validations_1_1 = validations_1.next();
3602
+ return [3 /*break*/, 3];
3603
+ case 13: return [3 /*break*/, 16];
3604
+ case 14:
3605
+ e_2_1 = _f.sent();
3606
+ e_2 = { error: e_2_1 };
3607
+ return [3 /*break*/, 16];
3608
+ case 15:
3609
+ try {
3610
+ if (validations_1_1 && !validations_1_1.done && (_d = validations_1.return)) _d.call(validations_1);
3611
+ }
3612
+ finally { if (e_2) throw e_2.error; }
3613
+ return [7 /*endfinally*/];
3614
+ case 16: return [4 /*yield*/, libraryToJson(library)];
3615
+ case 17:
3616
+ libraryJson = _f.sent();
3563
3617
  libraryJsonString = JSON.stringify(libraryJson);
3564
3618
  saveFile = function (extension, content) { return __awaiter(_this, void 0, void 0, function () {
3565
3619
  var filePath;
@@ -3575,25 +3629,25 @@
3575
3629
  }
3576
3630
  });
3577
3631
  }); };
3578
- if (!format.includes('json')) return [3 /*break*/, 4];
3632
+ if (!formats.includes('json')) return [3 /*break*/, 19];
3579
3633
  return [4 /*yield*/, saveFile('json', libraryJsonString + '\n')];
3580
- case 3:
3581
- _b.sent();
3582
- _b.label = 4;
3583
- case 4:
3584
- if (format.includes('javascript')) {
3634
+ case 18:
3635
+ _f.sent();
3636
+ _f.label = 19;
3637
+ case 19:
3638
+ if (formats.includes('javascript')) {
3585
3639
  // TODO: !!!!;
3586
3640
  // TODO: !!! DRY javascript and typescript
3587
- format.push('javascript');
3641
+ formats.push('javascript');
3588
3642
  }
3589
- if (!format.includes('typescript')) return [3 /*break*/, 6];
3643
+ if (!formats.includes('typescript')) return [3 /*break*/, 21];
3590
3644
  // TODO: !!!!!!!! Javascript json
3591
- return [4 /*yield*/, saveFile('ts', spaceTrim__default["default"]("\n import type { PromptbookLibrary, SimplePromptbookLibrary } from '@promptbook/types';\n import type { PromptbookLibrary } from '@promptbook/core';\n\n /**\n * Promptbook library for ".concat(projectName, "\n *\n * @private internal cache for `getPromptbookLibrary`\n */\n let promptbookLibrary: null | SimplePromptbookLibrary = null;\n\n\n /**\n * Get promptbook library for ").concat(projectName, "\n *\n * @returns {PromptbookLibrary} Library of promptbooks for ").concat(projectName, "\n * @generated by `@promptbook/cli`\n */\n export function getPromptbookLibrary(): PromptbookLibrary{\n if(promptbookLibrary===null){\n promptbookLibrary = createLibraryFromJson(...").concat(libraryJsonString, ");\n }\n\n return promptbookLibrary;\n }\n ") + '\n'))];
3592
- case 5:
3645
+ return [4 /*yield*/, saveFile('ts', spaceTrim__default["default"]("\n import type { PromptbookLibrary, SimplePromptbookLibrary } from '@promptbook/types';\n import type { createLibraryFromJson } from '@promptbook/core';\n\n /**\n * Promptbook library for ".concat(projectName, "\n *\n * @private internal cache for `getPromptbookLibrary`\n */\n let promptbookLibrary: null | SimplePromptbookLibrary = null;\n\n\n /**\n * Get promptbook library for ").concat(projectName, "\n *\n * @returns {PromptbookLibrary} Library of promptbooks for ").concat(projectName, "\n * @generated by `@promptbook/cli`\n */\n export function getPromptbookLibrary(): PromptbookLibrary{\n if(promptbookLibrary===null){\n promptbookLibrary = createLibraryFromJson(").concat(libraryJsonString.substring(1, libraryJsonString.length - 2), ");\n }\n\n return promptbookLibrary;\n }\n ") + '\n'))];
3646
+ case 20:
3593
3647
  // TODO: !!!!!!!! Javascript json
3594
- _b.sent();
3595
- _b.label = 6;
3596
- case 6:
3648
+ _f.sent();
3649
+ _f.label = 21;
3650
+ case 21:
3597
3651
  process.exit(0);
3598
3652
  return [2 /*return*/];
3599
3653
  }