@promptbook/cli 0.74.0-2 → 0.74.0-4

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
@@ -15,6 +15,7 @@ import { promisify } from 'util';
15
15
  import * as dotenv from 'dotenv';
16
16
  import sha256 from 'crypto-js/sha256';
17
17
  import glob from 'glob-promise';
18
+ import prompts from 'prompts';
18
19
  import { io } from 'socket.io-client';
19
20
  import Anthropic from '@anthropic-ai/sdk';
20
21
  import { OpenAIClient, AzureKeyCredential } from '@azure/openai';
@@ -35,7 +36,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
35
36
  *
36
37
  * @see https://github.com/webgptorg/promptbook
37
38
  */
38
- var PROMPTBOOK_ENGINE_VERSION = '0.74.0-1';
39
+ var PROMPTBOOK_ENGINE_VERSION = '0.74.0-3';
39
40
  /**
40
41
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
41
42
  */
@@ -584,8 +585,7 @@ function initializeAboutCommand(program) {
584
585
  console.info(colors.cyan("Promptbook engine version: ".concat(PROMPTBOOK_ENGINE_VERSION)));
585
586
  console.info(colors.cyan("https://github.com/webgptorg/promptbook"));
586
587
  console.info(colors.cyan("https://ptbk.io"));
587
- process.exit(0);
588
- return [2 /*return*/];
588
+ return [2 /*return*/, process.exit(0)];
589
589
  });
590
590
  }); });
591
591
  }
@@ -616,8 +616,7 @@ function initializeHelloCommand(program) {
616
616
  case 1:
617
617
  _b.sent();
618
618
  console.info(colors.rainbow("Nice to meet you!"));
619
- process.exit(0);
620
- return [2 /*return*/];
619
+ return [2 /*return*/, process.exit(0)];
621
620
  }
622
621
  });
623
622
  });
@@ -10232,7 +10231,7 @@ function initializeMakeCommand(program) {
10232
10231
  .filter(function (_) { return _ !== ''; });
10233
10232
  if (outFile !== DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME && formats.length !== 1) {
10234
10233
  console.error(colors.red("You can only use one format if you specify --out-file"));
10235
- process.exit(1);
10234
+ return [2 /*return*/, process.exit(1)];
10236
10235
  }
10237
10236
  options = {
10238
10237
  isVerbose: isVerbose,
@@ -10384,8 +10383,7 @@ function initializeMakeCommand(program) {
10384
10383
  if (isVerbose) {
10385
10384
  console.info(colors.cyan(usageToHuman(llm.getTotalUsage())));
10386
10385
  }
10387
- process.exit(0);
10388
- return [2 /*return*/];
10386
+ return [2 /*return*/, process.exit(0)];
10389
10387
  }
10390
10388
  });
10391
10389
  });
@@ -10593,8 +10591,7 @@ function initializePrettifyCommand(program) {
10593
10591
  console.info(colors.red("Prettify ".concat(error_1.name, " ").concat(filename)));
10594
10592
  console.error(colors.bgRed(error_1.name /* <- 11:11 */));
10595
10593
  console.error(colors.red(error_1.stack || error_1.message));
10596
- process.exit(1);
10597
- return [3 /*break*/, 9];
10594
+ return [2 /*return*/, process.exit(1)];
10598
10595
  case 9:
10599
10596
  filenames_1_1 = filenames_1.next();
10600
10597
  return [3 /*break*/, 3];
@@ -10611,8 +10608,7 @@ function initializePrettifyCommand(program) {
10611
10608
  return [7 /*endfinally*/];
10612
10609
  case 13:
10613
10610
  console.info(colors.green("All pipelines are prettified"));
10614
- process.exit(0);
10615
- return [2 /*return*/];
10611
+ return [2 /*return*/, process.exit(0)];
10616
10612
  }
10617
10613
  });
10618
10614
  });
@@ -10642,7 +10638,7 @@ function initializeRunCommand(program) {
10642
10638
  runCommand.action(function (path, _a) {
10643
10639
  var isCacheReloaded = _a.reload, isVerbose = _a.verbose;
10644
10640
  return __awaiter(_this, void 0, void 0, function () {
10645
- var options, fs, llm, executables, tools, pipelineString, pipeline, pipelineExecutor, inputParameters, result, isSuccessful, errors, outputParameters, executionReport, _b, _c, key, value, separator;
10641
+ var options, fs, llm, executables, tools, pipelineString, pipeline, questions, response, inputParameters, pipelineExecutor, result, isSuccessful, errors, outputParameters, executionReport, _b, _c, key, value, separator;
10646
10642
  var _d, e_1, _e;
10647
10643
  return __generator(this, function (_f) {
10648
10644
  switch (_f.label) {
@@ -10652,7 +10648,19 @@ function initializeRunCommand(program) {
10652
10648
  isCacheReloaded: isCacheReloaded,
10653
10649
  };
10654
10650
  fs = $provideFilesystemForNode(options);
10655
- llm = $provideLlmToolsForCli(options);
10651
+ try {
10652
+ llm = $provideLlmToolsForCli(options);
10653
+ }
10654
+ catch (error) {
10655
+ if (!(error instanceof Error)) {
10656
+ throw error;
10657
+ }
10658
+ if (!error.message.includes('No LLM tools')) {
10659
+ throw error;
10660
+ }
10661
+ console.error(colors.red(spaceTrim$1("\n You need to configure LLM tools first\n\n 1) Create .env file\n 2) Add OPENAI_API_KEY=...\n 3) *(and/or)* Add ANTHROPIC_CLAUDE_API_KEY=...\n ")));
10662
+ return [2 /*return*/, process.exit(1)];
10663
+ }
10656
10664
  return [4 /*yield*/, $provideExecutablesForNode(options)];
10657
10665
  case 1:
10658
10666
  executables = _f.sent();
@@ -10670,8 +10678,8 @@ function initializeRunCommand(program) {
10670
10678
  return [4 /*yield*/, isFileExisting(path, fs)];
10671
10679
  case 3:
10672
10680
  if (!(_f.sent())) {
10673
- throw new UnexpectedError("File \"".concat(path, "\" does not exist"));
10674
- // <- TODO: !!!!!! Catch and wrap all errors from CLI
10681
+ console.error(colors.red("File \"".concat(path, "\" does not exist")));
10682
+ return [2 /*return*/, process.exit(1)];
10675
10683
  }
10676
10684
  return [4 /*yield*/, fs.readFile(path, 'utf-8')];
10677
10685
  case 4:
@@ -10680,21 +10688,44 @@ function initializeRunCommand(program) {
10680
10688
  case 5:
10681
10689
  pipeline = _f.sent();
10682
10690
  validatePipeline(pipeline);
10691
+ questions = pipeline.parameters
10692
+ .filter(function (_a) {
10693
+ var isInput = _a.isInput;
10694
+ return isInput;
10695
+ })
10696
+ .map(function (_a) {
10697
+ var name = _a.name;
10698
+ return ({
10699
+ type: 'text',
10700
+ name: name,
10701
+ message: name,
10702
+ // TODO: Maybe use> validate: value => value < 18 ? `Forbidden` : true
10703
+ });
10704
+ });
10705
+ return [4 /*yield*/, prompts(questions)];
10706
+ case 6:
10707
+ response = _f.sent();
10708
+ inputParameters = response;
10709
+ // console.log(response);
10710
+ return [4 /*yield*/, forTime(100)];
10711
+ case 7:
10712
+ // console.log(response);
10713
+ _f.sent();
10683
10714
  pipelineExecutor = createPipelineExecutor({ pipeline: pipeline, tools: tools, isNotPreparedWarningSupressed: true });
10684
- inputParameters = {
10685
- eventTitle: 'OpenAlt',
10686
- eventDescription: "Konference OpenAlt vznikla v roce 2014 jako v\u00FDsledek spojen\u00ED konferenc\u00ED LinuxAlt a Openmobility. LinuxAlt jako konference s dlouhodobou tradic\u00ED se ji\u017E od roku 2006 v\u011Bnovala otev\u0159en\u00E9mu softwaru a technologi\u00EDm. Z\u00E1hy se LinuxAlt s v\u00EDce jak 500 n\u00E1v\u0161t\u011Bvn\u00EDky stal nejv\u011Bt\u0161\u00ED akc\u00ED tohoto typu v \u010Cesk\u00E9 republice. Openmobility konference vznikla v roce 2010 a p\u0159inesla \u010Desk\u00FDm a slovensk\u00FDm n\u00E1v\u0161t\u011Bvn\u00EDk\u016Fm t\u00E9mata otev\u0159en\u00FDch mobiln\u00EDch platforem a otev\u0159en\u00E9ho hardware formou klasick\u00FDch p\u0159edn\u00E1\u0161ek a praktick\u00FDch workshop\u016F. OpenAlt vych\u00E1z\u00ED z toho nejlep\u0161\u00EDho na LinuxAltu a Openmobility a roz\u0161i\u0159uje oblast sv\u00E9ho z\u00E1jmu o t\u00E9mata otev\u0159en\u00FDch dat ve st\u00E1tn\u00ED spr\u00E1v\u011B a soukrom\u00E9m sektoru (Open Data) a otev\u0159en\u00E9ho p\u0159\u00EDstupu k v\u011Bdeck\u00FDm informac\u00EDm (Open Access). OpenAlt se v\u011Bnuje tak\u00E9 participativn\u00ED a svobodn\u00E9 kultu\u0159e, zejm\u00E9na online spolupr\u00E1ci, u\u010D\u00EDc\u00EDm se komunit\u00E1m a v souvislosti s t\u00EDm i alternativn\u00EDmu vzd\u011Bl\u00E1v\u00E1n\u00ED. Na sv\u00E9 si p\u0159ijdou i novodob\u00ED kutilov\u00E9 (Makers) \u0159\u00EDd\u00EDc\u00ED se pravidlem \u201EUd\u011Blej si s\u00E1m\u201C (DIY).",
10687
- rules: '',
10688
- };
10689
10715
  return [4 /*yield*/, pipelineExecutor(inputParameters, function (taskProgress) {
10690
- // TODO: !!!!!!! Log if verbose
10691
- console.log(taskProgress);
10716
+ if (isVerbose) {
10717
+ // TODO: !!!!!!! Pretty print taskProgress
10718
+ console.log(taskProgress);
10719
+ }
10692
10720
  })];
10693
- case 6:
10721
+ case 8:
10694
10722
  result = _f.sent();
10695
10723
  isSuccessful = result.isSuccessful, errors = result.errors, outputParameters = result.outputParameters, executionReport = result.executionReport;
10696
- console.log({ isSuccessful: isSuccessful, errors: errors, outputParameters: outputParameters, executionReport: executionReport });
10697
- console.log(outputParameters);
10724
+ if (isVerbose) {
10725
+ // TODO: !!!!!!! Pretty print
10726
+ console.log({ isSuccessful: isSuccessful, errors: errors, outputParameters: outputParameters, executionReport: executionReport });
10727
+ console.log(outputParameters);
10728
+ }
10698
10729
  console.info(colors.gray('--- Result: ---'));
10699
10730
  try {
10700
10731
  for (_b = __values(Object.keys(outputParameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
@@ -10711,14 +10742,14 @@ function initializeRunCommand(program) {
10711
10742
  }
10712
10743
  finally { if (e_1) throw e_1.error; }
10713
10744
  }
10714
- process.exit(0);
10715
- return [2 /*return*/];
10745
+ return [2 /*return*/, process.exit(0)];
10716
10746
  }
10717
10747
  });
10718
10748
  });
10719
10749
  });
10720
10750
  }
10721
10751
  /**
10752
+ * TODO: !!!!!! Catch and wrap all errors from CLI
10722
10753
  * TODO: [🧠] Pass `maxExecutionAttempts`, `csvSettings`
10723
10754
  * TODO: [🥃][main] !!! Allow `ptbk run` without configuring any llm tools
10724
10755
  * Note: [🟡] Code in this file should never be published outside of `@promptbook/cli`
@@ -10818,8 +10849,7 @@ function initializeTestCommand(program) {
10818
10849
  console.info(colors.red("Pipeline is not valid ".concat(filename)));
10819
10850
  console.error(colors.bgRed(error_1.name /* <- 11:11 */));
10820
10851
  console.error(colors.red(error_1.stack || error_1.message));
10821
- process.exit(1);
10822
- return [3 /*break*/, 14];
10852
+ return [2 /*return*/, process.exit(1)];
10823
10853
  case 14:
10824
10854
  filenames_1_1 = filenames_1.next();
10825
10855
  return [3 /*break*/, 5];
@@ -10836,8 +10866,7 @@ function initializeTestCommand(program) {
10836
10866
  return [7 /*endfinally*/];
10837
10867
  case 18:
10838
10868
  console.info(colors.green("All pipelines are valid"));
10839
- process.exit(0);
10840
- return [2 /*return*/];
10869
+ return [2 /*return*/, process.exit(0)];
10841
10870
  }
10842
10871
  });
10843
10872
  });