@promptbook/cli 0.86.0-13 → 0.86.0-15

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/esm/index.es.js CHANGED
@@ -8,6 +8,7 @@ import hexEncoder from 'crypto-js/enc-hex';
8
8
  import sha256 from 'crypto-js/sha256';
9
9
  import * as dotenv from 'dotenv';
10
10
  import { spawn } from 'child_process';
11
+ import JSZip from 'jszip';
11
12
  import { format } from 'prettier';
12
13
  import parserHtml from 'prettier/parser-html';
13
14
  import { BehaviorSubject } from 'rxjs';
@@ -43,7 +44,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
43
44
  * @generated
44
45
  * @see https://github.com/webgptorg/promptbook
45
46
  */
46
- var PROMPTBOOK_ENGINE_VERSION = '0.86.0-13';
47
+ var PROMPTBOOK_ENGINE_VERSION = '0.86.0-15';
47
48
  /**
48
49
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
49
50
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -549,6 +550,7 @@ function $initializeHelloCommand(program) {
549
550
  var _this = this;
550
551
  var helloCommand = program.command('hello');
551
552
  helloCommand.description(spaceTrim("\n Just command for testing\n "));
553
+ helloCommand.alias('hi');
552
554
  helloCommand.argument('[name]', 'Your name', 'Paul');
553
555
  helloCommand.option('-g, --greeting <greeting>', "Greeting", 'Hello');
554
556
  helloCommand.action(function (name, _a) {
@@ -2922,6 +2924,8 @@ function $initializeListModelsCommand(program) {
2922
2924
  var _this = this;
2923
2925
  var listModelsCommand = program.command('list-models');
2924
2926
  listModelsCommand.description(spaceTrim("\n List all available and configured LLM models\n "));
2927
+ listModelsCommand.alias('models');
2928
+ listModelsCommand.alias('llm');
2925
2929
  listModelsCommand.action(function () { return __awaiter(_this, void 0, void 0, function () {
2926
2930
  var llm;
2927
2931
  return __generator(this, function (_a) {
@@ -3607,6 +3611,7 @@ function $initializeListScrapersCommand(program) {
3607
3611
  var _this = this;
3608
3612
  var listModelsCommand = program.command('list-scrapers');
3609
3613
  listModelsCommand.description(spaceTrim("\n List all available and configured scrapers and executables\n "));
3614
+ listModelsCommand.alias('scrapers');
3610
3615
  listModelsCommand.action(function () { return __awaiter(_this, void 0, void 0, function () {
3611
3616
  var scrapers, executables;
3612
3617
  return __generator(this, function (_a) {
@@ -3798,7 +3803,7 @@ function capitalize(word) {
3798
3803
  * Converts promptbook in JSON format to string format
3799
3804
  *
3800
3805
  * @deprecated TODO: [🥍][🧠] Backup original files in `PipelineJson` same as in Promptbook.studio
3801
- * @param pipelineJson Promptbook in JSON format (.book.json)
3806
+ * @param pipelineJson Promptbook in JSON format (.bookc)
3802
3807
  * @returns Promptbook in string format (.book.md)
3803
3808
  * @public exported from `@promptbook/core`
3804
3809
  */
@@ -10744,7 +10749,7 @@ function flattenMarkdown(markdown) {
10744
10749
  * Note: This function acts as compilation process
10745
10750
  *
10746
10751
  * @param pipelineString {Promptbook} in string markdown format (.book.md)
10747
- * @returns {Promptbook} compiled in JSON format (.book.json)
10752
+ * @returns {Promptbook} compiled in JSON format (.bookc)
10748
10753
  * @throws {ParseError} if the promptbook string is not valid
10749
10754
  * @public exported from `@promptbook/core`
10750
10755
  */
@@ -11212,7 +11217,7 @@ function parsePipeline(pipelineString) {
11212
11217
  * @param pipelineString {Promptbook} in string markdown format (.book.md)
11213
11218
  * @param tools - Tools for the preparation and scraping - if not provided together with `llm`, the preparation will be skipped
11214
11219
  * @param options - Options and tools for the compilation
11215
- * @returns {Promptbook} compiled in JSON format (.book.json)
11220
+ * @returns {Promptbook} compiled in JSON format (.bookc)
11216
11221
  * @throws {ParseError} if the promptbook string is not valid
11217
11222
  * @public exported from `@promptbook/core`
11218
11223
  */
@@ -12006,7 +12011,7 @@ function createCollectionFromDirectory(rootPath, tools, options) {
12006
12011
  }
12007
12012
  madeLibraryFilePath = join(rootPath, "".concat(DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME
12008
12013
  // <- TODO: [🦒] Allow to override (pass different value into the function)
12009
- , ".json"));
12014
+ , ".bookc"));
12010
12015
  return [4 /*yield*/, isFileExisting(madeLibraryFilePath, tools.fs)];
12011
12016
  case 3:
12012
12017
  if (!(_f.sent())) ;
@@ -12028,13 +12033,13 @@ function createCollectionFromDirectory(rootPath, tools, options) {
12028
12033
  return [4 /*yield*/, listAllFiles(rootPath, isRecursive, tools.fs)];
12029
12034
  case 1:
12030
12035
  fileNames = _b.sent();
12031
- // Note: First load all `.book.json` and then `.book` / `.book` files
12032
- // `.book.json` can be prepared so it is faster to load
12036
+ // Note: First load compiled `.bookc` files and then source `.book` files
12037
+ // `.bookc` are already compiled and can be used faster
12033
12038
  fileNames.sort(function (a, b) {
12034
- if (a.endsWith('.json') && (b.endsWith('.book') || b.endsWith('.book'))) {
12039
+ if ((a.endsWith('.bookc') || a.endsWith('.book.json')) && (b.endsWith('.book') || b.endsWith('.book.md'))) {
12035
12040
  return -1;
12036
12041
  }
12037
- if ((a.endsWith('.book') || a.endsWith('.book')) && b.endsWith('.json')) {
12042
+ if ((a.endsWith('.book') || a.endsWith('.book.md')) && (b.endsWith('.bookc') || b.endsWith('.book.json'))) {
12038
12043
  return 1;
12039
12044
  }
12040
12045
  return 0;
@@ -12051,7 +12056,7 @@ function createCollectionFromDirectory(rootPath, tools, options) {
12051
12056
  case 1:
12052
12057
  _f.trys.push([1, 8, , 9]);
12053
12058
  pipeline = null;
12054
- if (!(fileName.endsWith('.book') || fileName.endsWith('.book'))) return [3 /*break*/, 4];
12059
+ if (!(fileName.endsWith('.book') || fileName.endsWith('.book.md'))) return [3 /*break*/, 4];
12055
12060
  _c = validatePipelineString;
12056
12061
  return [4 /*yield*/, readFile(fileName, 'utf-8')];
12057
12062
  case 2:
@@ -12064,7 +12069,7 @@ function createCollectionFromDirectory(rootPath, tools, options) {
12064
12069
  pipeline = __assign(__assign({}, pipeline), { sourceFile: sourceFile });
12065
12070
  return [3 /*break*/, 7];
12066
12071
  case 4:
12067
- if (!fileName.endsWith('.book.json')) return [3 /*break*/, 6];
12072
+ if (!(fileName.endsWith('.bookc') || fileName.endsWith('.book.json'))) return [3 /*break*/, 6];
12068
12073
  _e = (_d = JSON).parse;
12069
12074
  return [4 /*yield*/, readFile(fileName, 'utf-8')];
12070
12075
  case 5:
@@ -12269,13 +12274,16 @@ function $initializeMakeCommand(program) {
12269
12274
  var _this = this;
12270
12275
  var makeCommand = program.command('make');
12271
12276
  makeCommand.description(spaceTrim("\n Makes a new pipeline collection in given folder\n "));
12277
+ makeCommand.alias('compile');
12278
+ makeCommand.alias('prepare');
12279
+ makeCommand.alias('build');
12272
12280
  // TODO: [🧅] DRY command arguments
12273
12281
  makeCommand.argument('[path]',
12274
12282
  // <- TODO: [🧟‍♂️] Unite path to promptbook collection argument
12275
12283
  'Path to promptbook collection directory', DEFAULT_BOOKS_DIRNAME);
12276
12284
  makeCommand.option('--project-name', "Name of the project for whom collection is", 'Untitled Promptbook project');
12277
12285
  makeCommand.option('--root-url <url>', "Root URL of all pipelines to make", undefined);
12278
- makeCommand.option('-f, --format <format>', spaceTrim("\n Output format of builded collection \"javascript\", \"typescript\" or \"json\"\n\n Note: You can use multiple formats separated by comma\n "), 'javascript' /* <- Note: [🏳‍🌈] */);
12286
+ makeCommand.option('-f, --format <format>', spaceTrim("\n Output format of builded collection \"bookc\", \"javascript\", \"typescript\" or \"json\"\n\n Note: You can use multiple formats separated by comma\n "), 'bookc' /* <- Note: [🏳‍🌈] */);
12279
12287
  makeCommand.option('--no-validation', "Do not validate logic of pipelines in collection", true);
12280
12288
  makeCommand.option('--validation', "Types of validations separated by comma (options \"logic\",\"imports\")", 'logic,imports');
12281
12289
  makeCommand.option('-r, --reload', "Call LLM models even if same prompt with result is in the cache", false);
@@ -12285,7 +12293,7 @@ function $initializeMakeCommand(program) {
12285
12293
  makeCommand.action(function (path, _a) {
12286
12294
  var projectName = _a.projectName, rootUrl = _a.rootUrl, format = _a.format, functionName = _a.functionName, validation = _a.validation, isCacheReloaded = _a.reload, isVerbose = _a.verbose, output = _a.output;
12287
12295
  return __awaiter(_this, void 0, void 0, function () {
12288
- var formats, validations, prepareAndScrapeOptions, fs, llm, executables, tools, collection, pipelinesUrls, validations_1, validations_1_1, validation_1, pipelinesUrls_1, pipelinesUrls_1_1, pipelineUrl, pipeline, e_1_1, e_2_1, collectionJson, collectionJsonString, collectionJsonItems, saveFile;
12296
+ var formats, validations, prepareAndScrapeOptions, fs, llm, executables, tools, collection, pipelinesUrls, validations_1, validations_1_1, validation_1, pipelinesUrls_1, pipelinesUrls_1_1, pipelineUrl, pipeline, e_1_1, e_2_1, collectionJson, collectionJsonString, collectionJsonItems, saveFile, bookcBundle;
12289
12297
  var _b, e_2, _c, e_1, _d;
12290
12298
  var _this = this;
12291
12299
  return __generator(this, function (_e) {
@@ -12421,7 +12429,7 @@ function $initializeMakeCommand(program) {
12421
12429
  return spaceTrim(collectionJsonString.substring(1, collectionJsonString.length - 1));
12422
12430
  })();
12423
12431
  saveFile = function (extension, content) { return __awaiter(_this, void 0, void 0, function () {
12424
- var filename;
12432
+ var filename, data;
12425
12433
  return __generator(this, function (_a) {
12426
12434
  switch (_a.label) {
12427
12435
  case 0:
@@ -12434,36 +12442,55 @@ function $initializeMakeCommand(program) {
12434
12442
  return [4 /*yield*/, mkdir(dirname(filename), { recursive: true })];
12435
12443
  case 1:
12436
12444
  _a.sent();
12445
+ if (!(typeof content === 'string')) return [3 /*break*/, 3];
12437
12446
  return [4 /*yield*/, writeFile(filename, content, 'utf-8')];
12438
12447
  case 2:
12439
12448
  _a.sent();
12449
+ return [3 /*break*/, 6];
12450
+ case 3: return [4 /*yield*/, content.generateAsync({ type: 'nodebuffer', streamFiles: true })];
12451
+ case 4:
12452
+ data = _a.sent();
12453
+ return [4 /*yield*/, writeFile(filename, data)];
12454
+ case 5:
12455
+ _a.sent();
12456
+ _a.label = 6;
12457
+ case 6:
12440
12458
  // Note: Log despite of verbose mode
12441
12459
  console.info(colors.green("Made ".concat(filename.split('\\').join('/'))));
12442
12460
  return [2 /*return*/];
12443
12461
  }
12444
12462
  });
12445
12463
  }); };
12446
- if (!formats.includes('json')) return [3 /*break*/, 22];
12447
- formats = formats.filter(function (format) { return format !== 'json'; });
12448
- return [4 /*yield*/, saveFile('json', collectionJsonString)];
12464
+ if (!formats.includes('bookc')) return [3 /*break*/, 22];
12465
+ formats = formats.filter(function (format) { return format !== 'bookc'; });
12466
+ bookcBundle = new JSZip();
12467
+ bookcBundle.file('index.book.json', collectionJsonString);
12468
+ return [4 /*yield*/, saveFile('bookc', bookcBundle)];
12449
12469
  case 21:
12450
12470
  _e.sent();
12451
12471
  _e.label = 22;
12452
12472
  case 22:
12453
- if (!(formats.includes('javascript') || formats.includes('js'))) return [3 /*break*/, 24];
12454
- formats = formats.filter(function (format) { return format !== 'javascript' && format !== 'js'; });
12455
- return [4 /*yield*/, saveFile('js', spaceTrim(function (block) { return "\n // ".concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n\n import { createCollectionFromJson } from '@promptbook/core';\n\n /**\n * Pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @generated\n * @private internal cache for `").concat(functionName, "`\n */\n let pipelineCollection = null;\n\n\n /**\n * Get pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @generated\n * @returns {PipelineCollection} Library of promptbooks for ").concat(projectName, "\n */\n export function ").concat(functionName, "(){\n if(pipelineCollection===null){\n pipelineCollection = createCollectionFromJson(\n ").concat(block(collectionJsonItems), "\n );\n }\n\n return pipelineCollection;\n }\n "); }))];
12473
+ if (!formats.includes('json')) return [3 /*break*/, 24];
12474
+ formats = formats.filter(function (format) { return format !== 'json'; });
12475
+ return [4 /*yield*/, saveFile('json', collectionJsonString)];
12456
12476
  case 23:
12457
- (_e.sent()) + '\n';
12477
+ _e.sent();
12458
12478
  _e.label = 24;
12459
12479
  case 24:
12460
- if (!(formats.includes('typescript') || formats.includes('ts'))) return [3 /*break*/, 26];
12461
- formats = formats.filter(function (format) { return format !== 'typescript' && format !== 'ts'; });
12462
- return [4 /*yield*/, saveFile('ts', spaceTrim(function (block) { return "\n // ".concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n\n import { createCollectionFromJson } from '@promptbook/core';\n import type { PipelineCollection } from '@promptbook/types';\n\n /**\n * Pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @private internal cache for `").concat(functionName, "`\n * @generated\n */\n let pipelineCollection: null | PipelineCollection = null;\n\n\n /**\n * Get pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @generated\n * @returns {PipelineCollection} Library of promptbooks for ").concat(projectName, "\n */\n export function ").concat(functionName, "(): PipelineCollection{\n if(pipelineCollection===null){\n\n // TODO: !!6 Use book string literal notation\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n pipelineCollection = (createCollectionFromJson as (..._: any) => PipelineCollection)(\n ").concat(block(collectionJsonItems), "\n );\n }\n\n return pipelineCollection;\n }\n "); }) + '\n')];
12480
+ if (!(formats.includes('javascript') || formats.includes('js'))) return [3 /*break*/, 26];
12481
+ formats = formats.filter(function (format) { return format !== 'javascript' && format !== 'js'; });
12482
+ return [4 /*yield*/, saveFile('js', spaceTrim(function (block) { return "\n // ".concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n\n import { createCollectionFromJson } from '@promptbook/core';\n\n /**\n * Pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @generated\n * @private internal cache for `").concat(functionName, "`\n */\n let pipelineCollection = null;\n\n\n /**\n * Get pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @generated\n * @returns {PipelineCollection} Library of promptbooks for ").concat(projectName, "\n */\n export function ").concat(functionName, "(){\n if(pipelineCollection===null){\n pipelineCollection = createCollectionFromJson(\n ").concat(block(collectionJsonItems), "\n );\n }\n\n return pipelineCollection;\n }\n "); }))];
12463
12483
  case 25:
12464
- _e.sent();
12484
+ (_e.sent()) + '\n';
12465
12485
  _e.label = 26;
12466
12486
  case 26:
12487
+ if (!(formats.includes('typescript') || formats.includes('ts'))) return [3 /*break*/, 28];
12488
+ formats = formats.filter(function (format) { return format !== 'typescript' && format !== 'ts'; });
12489
+ return [4 /*yield*/, saveFile('ts', spaceTrim(function (block) { return "\n // ".concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n\n import { createCollectionFromJson } from '@promptbook/core';\n import type { PipelineCollection } from '@promptbook/types';\n\n /**\n * Pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @private internal cache for `").concat(functionName, "`\n * @generated\n */\n let pipelineCollection: null | PipelineCollection = null;\n\n\n /**\n * Get pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @generated\n * @returns {PipelineCollection} Library of promptbooks for ").concat(projectName, "\n */\n export function ").concat(functionName, "(): PipelineCollection{\n if(pipelineCollection===null){\n\n // TODO: !!6 Use book string literal notation\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n pipelineCollection = (createCollectionFromJson as (..._: any) => PipelineCollection)(\n ").concat(block(collectionJsonItems), "\n );\n }\n\n return pipelineCollection;\n }\n "); }) + '\n')];
12490
+ case 27:
12491
+ _e.sent();
12492
+ _e.label = 28;
12493
+ case 28:
12467
12494
  if (formats.length > 0) {
12468
12495
  console.warn(colors.yellow("Format ".concat(formats.join(' and '), " is not supported")));
12469
12496
  }
@@ -13266,6 +13293,7 @@ function $initializeRunCommand(program) {
13266
13293
  var _this = this;
13267
13294
  var runCommand = program.command('run', { isDefault: true });
13268
13295
  runCommand.description(spaceTrim("\n Runs a pipeline\n "));
13296
+ runCommand.alias('execute');
13269
13297
  // TODO: [🧅] DRY command arguments
13270
13298
  runCommand.argument('[pipelineSource]', 'Path to book file OR URL to book file, if not provided it will be asked');
13271
13299
  runCommand.option('-r, --reload', "Call LLM models even if same prompt with result is in the cache", false);
@@ -13281,6 +13309,10 @@ function $initializeRunCommand(program) {
13281
13309
  switch (_m.label) {
13282
13310
  case 0:
13283
13311
  isCacheReloaded = options.reload, isInteractive = options.interactive, isFormfactorUsed = options.formfactor, json = options.json, isVerbose = options.verbose, saveReport = options.saveReport;
13312
+ if (pipelineSource.includes('-') && normalizeToKebabCase(pipelineSource) === pipelineSource) {
13313
+ console.error(colors.red("\"\"".concat(pipelineSource, "\" is not a valid command or book. See 'ptbk --help'.")));
13314
+ return [2 /*return*/, process.exit(1)];
13315
+ }
13284
13316
  if (saveReport && !saveReport.endsWith('.json') && !saveReport.endsWith('.md')) {
13285
13317
  console.error(colors.red("Report file must be .json or .md"));
13286
13318
  return [2 /*return*/, process.exit(1)];
@@ -14072,6 +14104,7 @@ function $initializeStartServerCommand(program) {
14072
14104
  startServerCommand.option('-r, --reload', "Call LLM models even if same prompt with result is in the cache", false);
14073
14105
  startServerCommand.option('-v, --verbose', "Is output verbose", false);
14074
14106
  startServerCommand.description(spaceTrim("\n Starts a remote server to execute books\n "));
14107
+ startServerCommand.alias('server');
14075
14108
  startServerCommand.action(function (path, _a) {
14076
14109
  var portRaw = _a.port, rawUrl = _a.url, isAnonymousModeAllowed = _a.allowAnonymous, isCacheReloaded = _a.reload, isVerbose = _a.verbose;
14077
14110
  return __awaiter(_this, void 0, void 0, function () {
@@ -14169,7 +14202,7 @@ function $initializeStartServerCommand(program) {
14169
14202
  function $initializeTestCommand(program) {
14170
14203
  var _this = this;
14171
14204
  var testCommand = program.command('test');
14172
- testCommand.description(spaceTrim("\n Iterates over `.book.md` and `.book.json` and checks if they are parsable and logically valid\n "));
14205
+ testCommand.description(spaceTrim("\n Iterates over `.book.md` and `.bookc` and checks if they are parsable and logically valid\n "));
14173
14206
  testCommand.argument('<filesGlob>',
14174
14207
  // <- TODO: [🧟‍♂️] Unite path to promptbook collection argument
14175
14208
  'Pipelines to test as glob pattern');
@@ -14234,7 +14267,7 @@ function $initializeTestCommand(program) {
14234
14267
  }
14235
14268
  _g.label = 10;
14236
14269
  case 10:
14237
- if (!filename.endsWith('.book.json')) return [3 /*break*/, 12];
14270
+ if (!filename.endsWith('.bookc')) return [3 /*break*/, 12];
14238
14271
  _d = (_c = JSON).parse;
14239
14272
  return [4 /*yield*/, readFile(filename, 'utf-8')];
14240
14273
  case 11: