@promptbook/cli 0.85.0-7 → 0.85.0-9

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
@@ -43,7 +43,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
43
43
  * @generated
44
44
  * @see https://github.com/webgptorg/promptbook
45
45
  */
46
- var PROMPTBOOK_ENGINE_VERSION = '0.85.0-6';
46
+ var PROMPTBOOK_ENGINE_VERSION = '0.85.0-8';
47
47
  /**
48
48
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
49
49
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -533,7 +533,6 @@ function $initializeAboutCommand(program) {
533
533
  }); });
534
534
  }
535
535
  /**
536
- * TODO: !!! Test this in `deno`
537
536
  * TODO: [🗽] Unite branding and make single place for it
538
537
  * Note: [💞] Ignore a discrepancy between file name and entity name
539
538
  * Note: [🟡] Code in this file should never be published outside of `@promptbook/cli`
@@ -4920,18 +4919,16 @@ function assertsTaskSuccessful(executionResult) {
4920
4919
  */
4921
4920
  function createTask(options) {
4922
4921
  var taskType = options.taskType, taskProcessCallback = options.taskProcessCallback;
4923
- var taskId = "".concat(taskType.toLowerCase().substring(0, 4), "-").concat($randomToken(8 /* <- TODO: !!! To global config + Use Base58 to avoid simmilar char conflicts */));
4922
+ var taskId = "".concat(taskType.toLowerCase().substring(0, 4), "-").concat($randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */));
4924
4923
  var partialResultSubject = new BehaviorSubject({});
4925
4924
  var finalResultPromise = /* not await */ taskProcessCallback(function (newOngoingResult) {
4926
4925
  partialResultSubject.next(newOngoingResult);
4927
4926
  });
4928
4927
  finalResultPromise
4929
4928
  .catch(function (error) {
4930
- // console.error('!!!!! Task failed:', error);
4931
4929
  partialResultSubject.error(error);
4932
4930
  })
4933
4931
  .then(function (value) {
4934
- // console.error('!!!!! Task finished:', value);
4935
4932
  if (value) {
4936
4933
  try {
4937
4934
  assertsTaskSuccessful(value);
@@ -4953,9 +4950,7 @@ function createTask(options) {
4953
4950
  return [4 /*yield*/, finalResultPromise];
4954
4951
  case 1:
4955
4952
  finalResult = _b.sent();
4956
- console.error('!!!!! finalResult:', finalResult);
4957
4953
  if (isCrashedOnError) {
4958
- console.error('!!!!! isCrashedOnError:', finalResult);
4959
4954
  assertsTaskSuccessful(finalResult);
4960
4955
  }
4961
4956
  return [2 /*return*/, finalResult];
@@ -13796,6 +13791,57 @@ function startRemoteServer(options) {
13796
13791
  .filter(function (part) { return part !== ''; })
13797
13792
  .join('/');
13798
13793
  var startupDate = new Date();
13794
+ function getExecutionToolsFromIdentification(identification) {
13795
+ return __awaiter(this, void 0, void 0, function () {
13796
+ var isAnonymous, llm, llmToolsConfiguration, appId, userId, customOptions, fs, executables, tools;
13797
+ var _a;
13798
+ return __generator(this, function (_b) {
13799
+ switch (_b.label) {
13800
+ case 0:
13801
+ if (identification === null || identification === undefined) {
13802
+ throw new Error("Identification is not provided");
13803
+ }
13804
+ isAnonymous = identification.isAnonymous;
13805
+ if (isAnonymous === true && !isAnonymousModeAllowed) {
13806
+ throw new PipelineExecutionError("Anonymous mode is not allowed"); // <- TODO: [main] !!3 Test
13807
+ }
13808
+ if (isAnonymous === false && !isApplicationModeAllowed) {
13809
+ throw new PipelineExecutionError("Application mode is not allowed"); // <- TODO: [main] !!3 Test
13810
+ }
13811
+ if (!(isAnonymous === true)) return [3 /*break*/, 1];
13812
+ llmToolsConfiguration = identification.llmToolsConfiguration;
13813
+ llm = createLlmToolsFromConfiguration(llmToolsConfiguration, { isVerbose: isVerbose });
13814
+ return [3 /*break*/, 4];
13815
+ case 1:
13816
+ if (!(isAnonymous === false && createLlmExecutionTools !== null)) return [3 /*break*/, 3];
13817
+ appId = identification.appId, userId = identification.userId, customOptions = identification.customOptions;
13818
+ return [4 /*yield*/, createLlmExecutionTools({
13819
+ appId: appId,
13820
+ userId: userId,
13821
+ customOptions: customOptions,
13822
+ })];
13823
+ case 2:
13824
+ llm = _b.sent();
13825
+ return [3 /*break*/, 4];
13826
+ case 3: throw new PipelineExecutionError("You must provide either llmToolsConfiguration or non-anonymous mode must be propperly configured");
13827
+ case 4:
13828
+ fs = $provideFilesystemForNode();
13829
+ return [4 /*yield*/, $provideExecutablesForNode()];
13830
+ case 5:
13831
+ executables = _b.sent();
13832
+ _a = {
13833
+ llm: llm,
13834
+ fs: fs
13835
+ };
13836
+ return [4 /*yield*/, $provideScrapersForNode({ fs: fs, llm: llm, executables: executables })];
13837
+ case 6:
13838
+ tools = (_a.scrapers = _b.sent(),
13839
+ _a);
13840
+ return [2 /*return*/, tools];
13841
+ }
13842
+ });
13843
+ });
13844
+ }
13799
13845
  var app = express();
13800
13846
  app.use(express.json());
13801
13847
  app.use(function (request, response, next) {
@@ -13889,13 +13935,12 @@ function startRemoteServer(options) {
13889
13935
  });
13890
13936
  }); });
13891
13937
  app.post("".concat(rootPath, "/executions/new"), function (request, response) { return __awaiter(_this, void 0, void 0, function () {
13892
- var inputParameters, pipelineUrl, pipeline, llm, fs, executables, tools, pipelineExecutor, executionTask, error_1;
13893
- var _a;
13938
+ var _a, inputParameters, identification, pipelineUrl, pipeline, tools, pipelineExecutor, executionTask, error_1;
13894
13939
  return __generator(this, function (_b) {
13895
13940
  switch (_b.label) {
13896
13941
  case 0:
13897
- _b.trys.push([0, 6, , 7]);
13898
- inputParameters = request.body.inputParameters;
13942
+ _b.trys.push([0, 4, , 5]);
13943
+ _a = request.body, inputParameters = _a.inputParameters, identification = _a.identification;
13899
13944
  pipelineUrl = request.body.pipelineUrl || request.body.book;
13900
13945
  return [4 /*yield*/, (collection === null || collection === void 0 ? void 0 : collection.getPipelineByUrl(pipelineUrl))];
13901
13946
  case 1:
@@ -13904,43 +13949,27 @@ function startRemoteServer(options) {
13904
13949
  response.status(404).send("Pipeline \"".concat(pipelineUrl, "\" not found"));
13905
13950
  return [2 /*return*/];
13906
13951
  }
13907
- return [4 /*yield*/, createLlmExecutionTools({
13908
- appId: '!!!!',
13909
- userId: '!!!!',
13910
- customOptions: {},
13911
- })];
13952
+ return [4 /*yield*/, getExecutionToolsFromIdentification(identification)];
13912
13953
  case 2:
13913
- llm = _b.sent();
13914
- fs = $provideFilesystemForNode();
13915
- return [4 /*yield*/, $provideExecutablesForNode()];
13916
- case 3:
13917
- executables = _b.sent();
13918
- _a = {
13919
- llm: llm,
13920
- fs: fs
13921
- };
13922
- return [4 /*yield*/, $provideScrapersForNode({ fs: fs, llm: llm, executables: executables })];
13923
- case 4:
13924
- tools = (_a.scrapers = _b.sent(),
13925
- _a);
13954
+ tools = _b.sent();
13926
13955
  pipelineExecutor = createPipelineExecutor(__assign({ pipeline: pipeline, tools: tools }, options));
13927
13956
  executionTask = pipelineExecutor(inputParameters);
13928
13957
  runningExecutionTasks.push(executionTask);
13929
13958
  return [4 /*yield*/, forTime(10)];
13930
- case 5:
13959
+ case 3:
13931
13960
  _b.sent();
13932
13961
  // <- Note: Wait for a while to wait for quick responses or sudden but asynchronous errors
13933
13962
  // <- TODO: Put this into configuration
13934
13963
  response.send(executionTask);
13935
- return [3 /*break*/, 7];
13936
- case 6:
13964
+ return [3 /*break*/, 5];
13965
+ case 4:
13937
13966
  error_1 = _b.sent();
13938
13967
  if (!(error_1 instanceof Error)) {
13939
13968
  throw error_1;
13940
13969
  }
13941
13970
  response.status(400).send({ error: serializeError(error_1) });
13942
- return [3 /*break*/, 7];
13943
- case 7: return [2 /*return*/];
13971
+ return [3 /*break*/, 5];
13972
+ case 5: return [2 /*return*/];
13944
13973
  }
13945
13974
  });
13946
13975
  }); });
@@ -13957,55 +13986,9 @@ function startRemoteServer(options) {
13957
13986
  if (isVerbose) {
13958
13987
  console.info(colors.gray("Client connected"), socket.id);
13959
13988
  }
13960
- var getExecutionToolsFromIdentification = function (identification) { return __awaiter(_this, void 0, void 0, function () {
13961
- var isAnonymous, llm, llmToolsConfiguration, appId, userId, customOptions, fs, executables, tools;
13962
- var _a;
13963
- return __generator(this, function (_b) {
13964
- switch (_b.label) {
13965
- case 0:
13966
- isAnonymous = identification.isAnonymous;
13967
- if (isAnonymous === true && !isAnonymousModeAllowed) {
13968
- throw new PipelineExecutionError("Anonymous mode is not allowed"); // <- TODO: [main] !!3 Test
13969
- }
13970
- if (isAnonymous === false && !isApplicationModeAllowed) {
13971
- throw new PipelineExecutionError("Application mode is not allowed"); // <- TODO: [main] !!3 Test
13972
- }
13973
- if (!(isAnonymous === true)) return [3 /*break*/, 1];
13974
- llmToolsConfiguration = identification.llmToolsConfiguration;
13975
- llm = createLlmToolsFromConfiguration(llmToolsConfiguration, { isVerbose: isVerbose });
13976
- return [3 /*break*/, 4];
13977
- case 1:
13978
- if (!(isAnonymous === false && createLlmExecutionTools !== null)) return [3 /*break*/, 3];
13979
- appId = identification.appId, userId = identification.userId, customOptions = identification.customOptions;
13980
- return [4 /*yield*/, createLlmExecutionTools({
13981
- appId: appId,
13982
- userId: userId,
13983
- customOptions: customOptions,
13984
- })];
13985
- case 2:
13986
- llm = _b.sent();
13987
- return [3 /*break*/, 4];
13988
- case 3: throw new PipelineExecutionError("You must provide either llmToolsConfiguration or non-anonymous mode must be propperly configured");
13989
- case 4:
13990
- fs = $provideFilesystemForNode();
13991
- return [4 /*yield*/, $provideExecutablesForNode()];
13992
- case 5:
13993
- executables = _b.sent();
13994
- _a = {
13995
- llm: llm,
13996
- fs: fs
13997
- };
13998
- return [4 /*yield*/, $provideScrapersForNode({ fs: fs, llm: llm, executables: executables })];
13999
- case 6:
14000
- tools = (_a.scrapers = _b.sent(),
14001
- _a);
14002
- return [2 /*return*/, tools];
14003
- }
14004
- });
14005
- }); };
14006
13989
  // -----------
14007
13990
  socket.on('prompt-request', function (request) { return __awaiter(_this, void 0, void 0, function () {
14008
- var identification, prompt, executionTools, llm, _a, promptResult, _b, error_2;
13991
+ var identification, prompt, tools, llm, _a, promptResult, _b, error_2;
14009
13992
  return __generator(this, function (_c) {
14010
13993
  switch (_c.label) {
14011
13994
  case 0:
@@ -14018,8 +14001,8 @@ function startRemoteServer(options) {
14018
14001
  _c.trys.push([1, 13, 14, 15]);
14019
14002
  return [4 /*yield*/, getExecutionToolsFromIdentification(identification)];
14020
14003
  case 2:
14021
- executionTools = _c.sent();
14022
- llm = executionTools.llm;
14004
+ tools = _c.sent();
14005
+ llm = tools.llm;
14023
14006
  _a = identification.isAnonymous === false &&
14024
14007
  collection !== null;
14025
14008
  if (!_a) return [3 /*break*/, 4];
@@ -14090,7 +14073,7 @@ function startRemoteServer(options) {
14090
14073
  // -----------
14091
14074
  // TODO: [👒] Listing models (and checking configuration) probbably should go through REST API not Socket.io
14092
14075
  socket.on('listModels-request', function (request) { return __awaiter(_this, void 0, void 0, function () {
14093
- var identification, executionTools, llm, models, error_3;
14076
+ var identification, tools, llm, models, error_3;
14094
14077
  return __generator(this, function (_a) {
14095
14078
  switch (_a.label) {
14096
14079
  case 0:
@@ -14103,8 +14086,8 @@ function startRemoteServer(options) {
14103
14086
  _a.trys.push([1, 4, 5, 6]);
14104
14087
  return [4 /*yield*/, getExecutionToolsFromIdentification(identification)];
14105
14088
  case 2:
14106
- executionTools = _a.sent();
14107
- llm = executionTools.llm;
14089
+ tools = _a.sent();
14090
+ llm = tools.llm;
14108
14091
  return [4 /*yield*/, llm.listModels()];
14109
14092
  case 3:
14110
14093
  models = _a.sent();
@@ -14127,7 +14110,7 @@ function startRemoteServer(options) {
14127
14110
  // -----------
14128
14111
  // TODO: [👒] Listing models (and checking configuration) probbably should go through REST API not Socket.io
14129
14112
  socket.on('preparePipeline-request', function (request) { return __awaiter(_this, void 0, void 0, function () {
14130
- var identification, pipeline, executionTools, preparedPipeline, error_4;
14113
+ var identification, pipeline, tools, preparedPipeline, error_4;
14131
14114
  return __generator(this, function (_a) {
14132
14115
  switch (_a.label) {
14133
14116
  case 0:
@@ -14140,8 +14123,8 @@ function startRemoteServer(options) {
14140
14123
  _a.trys.push([1, 4, 5, 6]);
14141
14124
  return [4 /*yield*/, getExecutionToolsFromIdentification(identification)];
14142
14125
  case 2:
14143
- executionTools = _a.sent();
14144
- return [4 /*yield*/, preparePipeline(pipeline, executionTools, options)];
14126
+ tools = _a.sent();
14127
+ return [4 /*yield*/, preparePipeline(pipeline, tools, options)];
14145
14128
  case 3:
14146
14129
  preparedPipeline = _a.sent();
14147
14130
  socket.emit('preparePipeline-response', { preparedPipeline: preparedPipeline } /* <- Note: [🤛] */);
@@ -14190,8 +14173,7 @@ function startRemoteServer(options) {
14190
14173
  };
14191
14174
  }
14192
14175
  /**
14193
- * TODO: !!!!!!! CORS and security
14194
- * TODO: !!!!!!! Allow to pass tokem here
14176
+ * TODO: !! Add CORS and security - probbably via `helmet`
14195
14177
  * TODO: [👩🏾‍🤝‍🧑🏾] Allow to pass custom fetch function here - PromptbookFetch
14196
14178
  * TODO: Split this file into multiple functions - handler for each request
14197
14179
  * TODO: Maybe use `$exportJson`
@@ -15530,7 +15512,7 @@ var OPENAI_MODELS = exportJson({
15530
15512
  pricing: {
15531
15513
  prompt: computeUsage("$3.00 / 1M tokens"),
15532
15514
  output: computeUsage("$12.00 / 1M tokens"),
15533
- // <- TODO: !!! Unsure, check the pricing
15515
+ // <- TODO: !! Unsure, check the pricing
15534
15516
  },
15535
15517
  },
15536
15518
  /**/
@@ -15542,7 +15524,7 @@ var OPENAI_MODELS = exportJson({
15542
15524
  pricing: {
15543
15525
  prompt: computeUsage("$3.00 / 1M tokens"),
15544
15526
  output: computeUsage("$12.00 / 1M tokens"),
15545
- // <- TODO: !!! Unsure, check the pricing
15527
+ // <- TODO: !! Unsure, check the pricing
15546
15528
  },
15547
15529
  },
15548
15530
  /**/