@promptbook/cli 0.85.0-8 → 0.85.0

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/README.md CHANGED
@@ -24,10 +24,6 @@
24
24
 
25
25
 
26
26
 
27
- <blockquote style="color: #ff8811">
28
- <b>⚠ Warning:</b> This is a pre-release version of the library. It is not yet ready for production use. Please look at <a href="https://www.npmjs.com/package/@promptbook/core?activeTab=versions">latest stable release</a>.
29
- </blockquote>
30
-
31
27
  ## 📦 Package `@promptbook/cli`
32
28
 
33
29
  - Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
package/esm/index.es.js CHANGED
@@ -2,7 +2,7 @@ import colors from 'colors';
2
2
  import commander from 'commander';
3
3
  import spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
4
4
  import { forTime, forEver } from 'waitasecond';
5
- import { basename, join, dirname } from 'path';
5
+ import { basename, join, dirname, relative } from 'path';
6
6
  import { stat, access, constants, readFile, writeFile, readdir, mkdir, unlink, rm, rmdir, rename } from 'fs/promises';
7
7
  import hexEncoder from 'crypto-js/enc-hex';
8
8
  import sha256 from 'crypto-js/sha256';
@@ -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-7';
46
+ var PROMPTBOOK_ENGINE_VERSION = '0.85.0-16';
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`
@@ -4060,57 +4059,6 @@ function isValidPromptbookVersion(version) {
4060
4059
  return true;
4061
4060
  }
4062
4061
 
4063
- /**
4064
- * Checks if an URL is reserved for private networks or localhost.
4065
- *
4066
- * Note: There are two simmilar functions:
4067
- * - `isUrlOnPrivateNetwork` which tests full URL
4068
- * - `isHostnameOnPrivateNetwork` *(this one)* which tests just hostname
4069
- *
4070
- * @public exported from `@promptbook/utils`
4071
- */
4072
- function isHostnameOnPrivateNetwork(hostname) {
4073
- if (hostname === 'example.com' ||
4074
- hostname === 'localhost' ||
4075
- hostname.endsWith('.localhost') ||
4076
- hostname.endsWith('.local') ||
4077
- hostname.endsWith('.test') ||
4078
- hostname === '127.0.0.1' ||
4079
- hostname === '::1') {
4080
- return true;
4081
- }
4082
- if (hostname.includes(':')) {
4083
- // IPv6
4084
- var ipParts = hostname.split(':');
4085
- return ipParts[0] === 'fc00' || ipParts[0] === 'fd00' || ipParts[0] === 'fe80';
4086
- }
4087
- else {
4088
- // IPv4
4089
- var ipParts = hostname.split('.').map(function (part) { return Number.parseInt(part, 10); });
4090
- return (ipParts[0] === 10 ||
4091
- (ipParts[0] === 172 && ipParts[1] >= 16 && ipParts[1] <= 31) ||
4092
- (ipParts[0] === 192 && ipParts[1] === 168));
4093
- }
4094
- }
4095
-
4096
- /**
4097
- * Checks if an IP address or hostname is reserved for private networks or localhost.
4098
- *
4099
- * Note: There are two simmilar functions:
4100
- * - `isUrlOnPrivateNetwork` *(this one)* which tests full URL
4101
- * - `isHostnameOnPrivateNetwork` which tests just hostname
4102
- *
4103
- * @param {string} ipAddress - The IP address to check.
4104
- * @returns {boolean} Returns true if the IP address is reserved for private networks or localhost, otherwise false.
4105
- * @public exported from `@promptbook/utils`
4106
- */
4107
- function isUrlOnPrivateNetwork(url) {
4108
- if (typeof url === 'string') {
4109
- url = new URL(url);
4110
- }
4111
- return isHostnameOnPrivateNetwork(url.hostname);
4112
- }
4113
-
4114
4062
  /**
4115
4063
  * Tests if given string is valid pipeline URL URL.
4116
4064
  *
@@ -4124,16 +4072,19 @@ function isValidPipelineUrl(url) {
4124
4072
  if (!isValidUrl(url)) {
4125
4073
  return false;
4126
4074
  }
4127
- if (!url.startsWith('https://')) {
4075
+ if (!url.startsWith('https://') && !url.startsWith('http://') /* <- Note: [👣] */) {
4128
4076
  return false;
4129
4077
  }
4130
4078
  if (url.includes('#')) {
4131
4079
  // TODO: [🐠]
4132
4080
  return false;
4133
4081
  }
4082
+ /*
4083
+ Note: [👣][🧠] Is it secure to allow pipeline URLs on private and unsecured networks?
4134
4084
  if (isUrlOnPrivateNetwork(url)) {
4135
4085
  return false;
4136
4086
  }
4087
+ */
4137
4088
  return true;
4138
4089
  }
4139
4090
  /**
@@ -4920,18 +4871,16 @@ function assertsTaskSuccessful(executionResult) {
4920
4871
  */
4921
4872
  function createTask(options) {
4922
4873
  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 */));
4874
+ var taskId = "".concat(taskType.toLowerCase().substring(0, 4), "-").concat($randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */));
4924
4875
  var partialResultSubject = new BehaviorSubject({});
4925
4876
  var finalResultPromise = /* not await */ taskProcessCallback(function (newOngoingResult) {
4926
4877
  partialResultSubject.next(newOngoingResult);
4927
4878
  });
4928
4879
  finalResultPromise
4929
4880
  .catch(function (error) {
4930
- // console.error('!!!!! Task failed:', error);
4931
4881
  partialResultSubject.error(error);
4932
4882
  })
4933
4883
  .then(function (value) {
4934
- // console.error('!!!!! Task finished:', value);
4935
4884
  if (value) {
4936
4885
  try {
4937
4886
  assertsTaskSuccessful(value);
@@ -4953,9 +4902,7 @@ function createTask(options) {
4953
4902
  return [4 /*yield*/, finalResultPromise];
4954
4903
  case 1:
4955
4904
  finalResult = _b.sent();
4956
- console.error('!!!!! finalResult:', finalResult);
4957
4905
  if (isCrashedOnError) {
4958
- console.error('!!!!! isCrashedOnError:', finalResult);
4959
4906
  assertsTaskSuccessful(finalResult);
4960
4907
  }
4961
4908
  return [2 /*return*/, finalResult];
@@ -12034,13 +11981,13 @@ function createCollectionFromPromise(promptbookSourcesPromiseOrFactory) {
12034
11981
  *
12035
11982
  * Note: Works only in Node.js environment because it reads the file system
12036
11983
  *
12037
- * @param path - path to the directory with pipelines
11984
+ * @param rootPath - path to the directory with pipelines
12038
11985
  * @param tools - Execution tools to be used for pipeline preparation if needed - If not provided, `$provideExecutionToolsForNode` will be used
12039
11986
  * @param options - Options for the collection creation
12040
11987
  * @returns PipelineCollection
12041
11988
  * @public exported from `@promptbook/node`
12042
11989
  */
12043
- function createCollectionFromDirectory(path, tools, options) {
11990
+ function createCollectionFromDirectory(rootPath, tools, options) {
12044
11991
  return __awaiter(this, void 0, void 0, function () {
12045
11992
  var madeLibraryFilePath, _a, _b, isRecursive, _c, isVerbose, _d, isLazyLoaded, _e, isCrashedOnError, rootUrl, collection;
12046
11993
  var _this = this;
@@ -12057,7 +12004,7 @@ function createCollectionFromDirectory(path, tools, options) {
12057
12004
  throw new EnvironmentMismatchError('Can not create collection without filesystem tools');
12058
12005
  // <- TODO: [🧠] What is the best error type here`
12059
12006
  }
12060
- madeLibraryFilePath = join(path, "".concat(DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME
12007
+ madeLibraryFilePath = join(rootPath, "".concat(DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME
12061
12008
  // <- TODO: [🦒] Allow to override (pass different value into the function)
12062
12009
  , ".json"));
12063
12010
  return [4 /*yield*/, isFileExisting(madeLibraryFilePath, tools.fs)];
@@ -12076,18 +12023,18 @@ function createCollectionFromDirectory(path, tools, options) {
12076
12023
  switch (_b.label) {
12077
12024
  case 0:
12078
12025
  if (isVerbose) {
12079
- console.info(colors.cyan("Creating pipeline collection from path ".concat(path.split('\\').join('/'))));
12026
+ console.info(colors.cyan("Creating pipeline collection from path ".concat(rootPath.split('\\').join('/'))));
12080
12027
  }
12081
- return [4 /*yield*/, listAllFiles(path, isRecursive, tools.fs)];
12028
+ return [4 /*yield*/, listAllFiles(rootPath, isRecursive, tools.fs)];
12082
12029
  case 1:
12083
12030
  fileNames = _b.sent();
12084
- // Note: First load all .book.json and then .book.md files
12085
- // .book.json can be prepared so it is faster to load
12031
+ // Note: First load all `.book.json` and then `.book` / `.book.md` files
12032
+ // `.book.json` can be prepared so it is faster to load
12086
12033
  fileNames.sort(function (a, b) {
12087
- if (a.endsWith('.json') && b.endsWith('.md')) {
12034
+ if (a.endsWith('.json') && (b.endsWith('.book') || b.endsWith('.book.md'))) {
12088
12035
  return -1;
12089
12036
  }
12090
- if (a.endsWith('.md') && b.endsWith('.json')) {
12037
+ if ((a.endsWith('.book') || a.endsWith('.book.md')) && b.endsWith('.json')) {
12091
12038
  return 1;
12092
12039
  }
12093
12040
  return 0;
@@ -12104,7 +12051,7 @@ function createCollectionFromDirectory(path, tools, options) {
12104
12051
  case 1:
12105
12052
  _f.trys.push([1, 8, , 9]);
12106
12053
  pipeline = null;
12107
- if (!fileName.endsWith('.book.md')) return [3 /*break*/, 4];
12054
+ if (!(fileName.endsWith('.book') || fileName.endsWith('.book.md'))) return [3 /*break*/, 4];
12108
12055
  _c = validatePipelineString;
12109
12056
  return [4 /*yield*/, readFile(fileName, 'utf-8')];
12110
12057
  case 2:
@@ -12136,7 +12083,8 @@ function createCollectionFromDirectory(path, tools, options) {
12136
12083
  if (pipeline !== null) {
12137
12084
  if (rootUrl !== undefined) {
12138
12085
  if (pipeline.pipelineUrl === undefined) {
12139
- pipelineUrl = rootUrl + '/' + fileName.split('\\').join('/');
12086
+ pipelineUrl = rootUrl + '/' + relative(rootPath, fileName).split('\\').join('/');
12087
+ // console.log({ pipelineUrl, rootPath, rootUrl, fileName });
12140
12088
  if (isVerbose) {
12141
12089
  console.info(colors.yellow("Implicitly set pipeline URL to ".concat(pipelineUrl, " from ").concat(fileName
12142
12090
  .split('\\')
@@ -13796,6 +13744,57 @@ function startRemoteServer(options) {
13796
13744
  .filter(function (part) { return part !== ''; })
13797
13745
  .join('/');
13798
13746
  var startupDate = new Date();
13747
+ function getExecutionToolsFromIdentification(identification) {
13748
+ return __awaiter(this, void 0, void 0, function () {
13749
+ var isAnonymous, llm, llmToolsConfiguration, appId, userId, customOptions, fs, executables, tools;
13750
+ var _a;
13751
+ return __generator(this, function (_b) {
13752
+ switch (_b.label) {
13753
+ case 0:
13754
+ if (identification === null || identification === undefined) {
13755
+ throw new Error("Identification is not provided");
13756
+ }
13757
+ isAnonymous = identification.isAnonymous;
13758
+ if (isAnonymous === true && !isAnonymousModeAllowed) {
13759
+ throw new PipelineExecutionError("Anonymous mode is not allowed"); // <- TODO: [main] !!3 Test
13760
+ }
13761
+ if (isAnonymous === false && !isApplicationModeAllowed) {
13762
+ throw new PipelineExecutionError("Application mode is not allowed"); // <- TODO: [main] !!3 Test
13763
+ }
13764
+ if (!(isAnonymous === true)) return [3 /*break*/, 1];
13765
+ llmToolsConfiguration = identification.llmToolsConfiguration;
13766
+ llm = createLlmToolsFromConfiguration(llmToolsConfiguration, { isVerbose: isVerbose });
13767
+ return [3 /*break*/, 4];
13768
+ case 1:
13769
+ if (!(isAnonymous === false && createLlmExecutionTools !== null)) return [3 /*break*/, 3];
13770
+ appId = identification.appId, userId = identification.userId, customOptions = identification.customOptions;
13771
+ return [4 /*yield*/, createLlmExecutionTools({
13772
+ appId: appId,
13773
+ userId: userId,
13774
+ customOptions: customOptions,
13775
+ })];
13776
+ case 2:
13777
+ llm = _b.sent();
13778
+ return [3 /*break*/, 4];
13779
+ case 3: throw new PipelineExecutionError("You must provide either llmToolsConfiguration or non-anonymous mode must be propperly configured");
13780
+ case 4:
13781
+ fs = $provideFilesystemForNode();
13782
+ return [4 /*yield*/, $provideExecutablesForNode()];
13783
+ case 5:
13784
+ executables = _b.sent();
13785
+ _a = {
13786
+ llm: llm,
13787
+ fs: fs
13788
+ };
13789
+ return [4 /*yield*/, $provideScrapersForNode({ fs: fs, llm: llm, executables: executables })];
13790
+ case 6:
13791
+ tools = (_a.scrapers = _b.sent(),
13792
+ _a);
13793
+ return [2 /*return*/, tools];
13794
+ }
13795
+ });
13796
+ });
13797
+ }
13799
13798
  var app = express();
13800
13799
  app.use(express.json());
13801
13800
  app.use(function (request, response, next) {
@@ -13869,6 +13868,46 @@ function startRemoteServer(options) {
13869
13868
  }
13870
13869
  });
13871
13870
  }); });
13871
+ // TODO: [🧠] Is it secure / good idea to expose source codes of hosted books
13872
+ app.get("".concat(rootPath, "/books/*"), function (request, response) { return __awaiter(_this, void 0, void 0, function () {
13873
+ var pipelines, fullUrl, pipelineUrl, pipeline, source, error_1;
13874
+ return __generator(this, function (_a) {
13875
+ switch (_a.label) {
13876
+ case 0:
13877
+ _a.trys.push([0, 3, , 4]);
13878
+ if (collection === null) {
13879
+ response.status(500).send('No collection nor books available');
13880
+ return [2 /*return*/];
13881
+ }
13882
+ return [4 /*yield*/, collection.listPipelines()];
13883
+ case 1:
13884
+ pipelines = _a.sent();
13885
+ fullUrl = request.protocol + '://' + request.get('host') + request.originalUrl;
13886
+ pipelineUrl = pipelines.find(function (pipelineUrl) { return pipelineUrl.endsWith(request.originalUrl); }) || fullUrl;
13887
+ return [4 /*yield*/, collection.getPipelineByUrl(pipelineUrl)];
13888
+ case 2:
13889
+ pipeline = _a.sent();
13890
+ source = pipeline.sources[0];
13891
+ if (source === undefined || source.type !== 'BOOK') {
13892
+ throw new Error('Pipeline source is not a book');
13893
+ }
13894
+ response
13895
+ .type('text/markdown')
13896
+ .send(source.content);
13897
+ return [3 /*break*/, 4];
13898
+ case 3:
13899
+ error_1 = _a.sent();
13900
+ if (!(error_1 instanceof Error)) {
13901
+ throw error_1;
13902
+ }
13903
+ response
13904
+ .status(404)
13905
+ .send({ error: serializeError(error_1) });
13906
+ return [3 /*break*/, 4];
13907
+ case 4: return [2 /*return*/];
13908
+ }
13909
+ });
13910
+ }); });
13872
13911
  app.get("".concat(rootPath, "/executions"), function (request, response) { return __awaiter(_this, void 0, void 0, function () {
13873
13912
  return __generator(this, function (_a) {
13874
13913
  response.send(runningExecutionTasks);
@@ -13881,7 +13920,9 @@ function startRemoteServer(options) {
13881
13920
  taskId = request.params.taskId;
13882
13921
  execution = runningExecutionTasks.find(function (executionTask) { return executionTask.taskId === taskId; });
13883
13922
  if (execution === undefined) {
13884
- response.status(404).send("Execution \"".concat(taskId, "\" not found"));
13923
+ response
13924
+ .status(404)
13925
+ .send("Execution \"".concat(taskId, "\" not found"));
13885
13926
  return [2 /*return*/];
13886
13927
  }
13887
13928
  response.send(execution.currentValue);
@@ -13889,13 +13930,12 @@ function startRemoteServer(options) {
13889
13930
  });
13890
13931
  }); });
13891
13932
  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;
13933
+ var _a, inputParameters, identification, pipelineUrl, pipeline, tools, pipelineExecutor, executionTask, error_2;
13894
13934
  return __generator(this, function (_b) {
13895
13935
  switch (_b.label) {
13896
13936
  case 0:
13897
- _b.trys.push([0, 6, , 7]);
13898
- inputParameters = request.body.inputParameters;
13937
+ _b.trys.push([0, 4, , 5]);
13938
+ _a = request.body, inputParameters = _a.inputParameters, identification = _a.identification;
13899
13939
  pipelineUrl = request.body.pipelineUrl || request.body.book;
13900
13940
  return [4 /*yield*/, (collection === null || collection === void 0 ? void 0 : collection.getPipelineByUrl(pipelineUrl))];
13901
13941
  case 1:
@@ -13904,43 +13944,27 @@ function startRemoteServer(options) {
13904
13944
  response.status(404).send("Pipeline \"".concat(pipelineUrl, "\" not found"));
13905
13945
  return [2 /*return*/];
13906
13946
  }
13907
- return [4 /*yield*/, createLlmExecutionTools({
13908
- appId: '!!!!',
13909
- userId: '!!!!',
13910
- customOptions: {},
13911
- })];
13947
+ return [4 /*yield*/, getExecutionToolsFromIdentification(identification)];
13912
13948
  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);
13949
+ tools = _b.sent();
13926
13950
  pipelineExecutor = createPipelineExecutor(__assign({ pipeline: pipeline, tools: tools }, options));
13927
13951
  executionTask = pipelineExecutor(inputParameters);
13928
13952
  runningExecutionTasks.push(executionTask);
13929
13953
  return [4 /*yield*/, forTime(10)];
13930
- case 5:
13954
+ case 3:
13931
13955
  _b.sent();
13932
13956
  // <- Note: Wait for a while to wait for quick responses or sudden but asynchronous errors
13933
13957
  // <- TODO: Put this into configuration
13934
13958
  response.send(executionTask);
13935
- return [3 /*break*/, 7];
13936
- case 6:
13937
- error_1 = _b.sent();
13938
- if (!(error_1 instanceof Error)) {
13939
- throw error_1;
13959
+ return [3 /*break*/, 5];
13960
+ case 4:
13961
+ error_2 = _b.sent();
13962
+ if (!(error_2 instanceof Error)) {
13963
+ throw error_2;
13940
13964
  }
13941
- response.status(400).send({ error: serializeError(error_1) });
13942
- return [3 /*break*/, 7];
13943
- case 7: return [2 /*return*/];
13965
+ response.status(400).send({ error: serializeError(error_2) });
13966
+ return [3 /*break*/, 5];
13967
+ case 5: return [2 /*return*/];
13944
13968
  }
13945
13969
  });
13946
13970
  }); });
@@ -13957,55 +13981,9 @@ function startRemoteServer(options) {
13957
13981
  if (isVerbose) {
13958
13982
  console.info(colors.gray("Client connected"), socket.id);
13959
13983
  }
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
13984
  // -----------
14007
13985
  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;
13986
+ var identification, prompt, tools, llm, _a, promptResult, _b, error_3;
14009
13987
  return __generator(this, function (_c) {
14010
13988
  switch (_c.label) {
14011
13989
  case 0:
@@ -14018,8 +13996,8 @@ function startRemoteServer(options) {
14018
13996
  _c.trys.push([1, 13, 14, 15]);
14019
13997
  return [4 /*yield*/, getExecutionToolsFromIdentification(identification)];
14020
13998
  case 2:
14021
- executionTools = _c.sent();
14022
- llm = executionTools.llm;
13999
+ tools = _c.sent();
14000
+ llm = tools.llm;
14023
14001
  _a = identification.isAnonymous === false &&
14024
14002
  collection !== null;
14025
14003
  if (!_a) return [3 /*break*/, 4];
@@ -14074,11 +14052,11 @@ function startRemoteServer(options) {
14074
14052
  socket.emit('prompt-response', { promptResult: promptResult } /* <- Note: [🤛] */);
14075
14053
  return [3 /*break*/, 15];
14076
14054
  case 13:
14077
- error_2 = _c.sent();
14078
- if (!(error_2 instanceof Error)) {
14079
- throw error_2;
14055
+ error_3 = _c.sent();
14056
+ if (!(error_3 instanceof Error)) {
14057
+ throw error_3;
14080
14058
  }
14081
- socket.emit('error', serializeError(error_2) /* <- Note: [🤛] */);
14059
+ socket.emit('error', serializeError(error_3) /* <- Note: [🤛] */);
14082
14060
  return [3 /*break*/, 15];
14083
14061
  case 14:
14084
14062
  socket.disconnect();
@@ -14090,7 +14068,7 @@ function startRemoteServer(options) {
14090
14068
  // -----------
14091
14069
  // TODO: [👒] Listing models (and checking configuration) probbably should go through REST API not Socket.io
14092
14070
  socket.on('listModels-request', function (request) { return __awaiter(_this, void 0, void 0, function () {
14093
- var identification, executionTools, llm, models, error_3;
14071
+ var identification, tools, llm, models, error_4;
14094
14072
  return __generator(this, function (_a) {
14095
14073
  switch (_a.label) {
14096
14074
  case 0:
@@ -14103,19 +14081,19 @@ function startRemoteServer(options) {
14103
14081
  _a.trys.push([1, 4, 5, 6]);
14104
14082
  return [4 /*yield*/, getExecutionToolsFromIdentification(identification)];
14105
14083
  case 2:
14106
- executionTools = _a.sent();
14107
- llm = executionTools.llm;
14084
+ tools = _a.sent();
14085
+ llm = tools.llm;
14108
14086
  return [4 /*yield*/, llm.listModels()];
14109
14087
  case 3:
14110
14088
  models = _a.sent();
14111
14089
  socket.emit('listModels-response', { models: models } /* <- Note: [🤛] */);
14112
14090
  return [3 /*break*/, 6];
14113
14091
  case 4:
14114
- error_3 = _a.sent();
14115
- if (!(error_3 instanceof Error)) {
14116
- throw error_3;
14092
+ error_4 = _a.sent();
14093
+ if (!(error_4 instanceof Error)) {
14094
+ throw error_4;
14117
14095
  }
14118
- socket.emit('error', serializeError(error_3));
14096
+ socket.emit('error', serializeError(error_4));
14119
14097
  return [3 /*break*/, 6];
14120
14098
  case 5:
14121
14099
  socket.disconnect();
@@ -14127,7 +14105,7 @@ function startRemoteServer(options) {
14127
14105
  // -----------
14128
14106
  // TODO: [👒] Listing models (and checking configuration) probbably should go through REST API not Socket.io
14129
14107
  socket.on('preparePipeline-request', function (request) { return __awaiter(_this, void 0, void 0, function () {
14130
- var identification, pipeline, executionTools, preparedPipeline, error_4;
14108
+ var identification, pipeline, tools, preparedPipeline, error_5;
14131
14109
  return __generator(this, function (_a) {
14132
14110
  switch (_a.label) {
14133
14111
  case 0:
@@ -14140,18 +14118,18 @@ function startRemoteServer(options) {
14140
14118
  _a.trys.push([1, 4, 5, 6]);
14141
14119
  return [4 /*yield*/, getExecutionToolsFromIdentification(identification)];
14142
14120
  case 2:
14143
- executionTools = _a.sent();
14144
- return [4 /*yield*/, preparePipeline(pipeline, executionTools, options)];
14121
+ tools = _a.sent();
14122
+ return [4 /*yield*/, preparePipeline(pipeline, tools, options)];
14145
14123
  case 3:
14146
14124
  preparedPipeline = _a.sent();
14147
14125
  socket.emit('preparePipeline-response', { preparedPipeline: preparedPipeline } /* <- Note: [🤛] */);
14148
14126
  return [3 /*break*/, 6];
14149
14127
  case 4:
14150
- error_4 = _a.sent();
14151
- if (!(error_4 instanceof Error)) {
14152
- throw error_4;
14128
+ error_5 = _a.sent();
14129
+ if (!(error_5 instanceof Error)) {
14130
+ throw error_5;
14153
14131
  }
14154
- socket.emit('error', serializeError(error_4));
14132
+ socket.emit('error', serializeError(error_5));
14155
14133
  return [3 /*break*/, 6];
14156
14134
  case 5:
14157
14135
  socket.disconnect();
@@ -14190,8 +14168,7 @@ function startRemoteServer(options) {
14190
14168
  };
14191
14169
  }
14192
14170
  /**
14193
- * TODO: !!!!!!! CORS and security
14194
- * TODO: !!!!!!! Allow to pass tokem here
14171
+ * TODO: !! Add CORS and security - probbably via `helmet`
14195
14172
  * TODO: [👩🏾‍🤝‍🧑🏾] Allow to pass custom fetch function here - PromptbookFetch
14196
14173
  * TODO: Split this file into multiple functions - handler for each request
14197
14174
  * TODO: Maybe use `$exportJson`
@@ -15530,7 +15507,7 @@ var OPENAI_MODELS = exportJson({
15530
15507
  pricing: {
15531
15508
  prompt: computeUsage("$3.00 / 1M tokens"),
15532
15509
  output: computeUsage("$12.00 / 1M tokens"),
15533
- // <- TODO: !!! Unsure, check the pricing
15510
+ // <- TODO: !! Unsure, check the pricing
15534
15511
  },
15535
15512
  },
15536
15513
  /**/
@@ -15542,7 +15519,7 @@ var OPENAI_MODELS = exportJson({
15542
15519
  pricing: {
15543
15520
  prompt: computeUsage("$3.00 / 1M tokens"),
15544
15521
  output: computeUsage("$12.00 / 1M tokens"),
15545
- // <- TODO: !!! Unsure, check the pricing
15522
+ // <- TODO: !! Unsure, check the pricing
15546
15523
  },
15547
15524
  },
15548
15525
  /**/