@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.
@@ -8,7 +8,6 @@ import type { Command as Program } from 'commander';
8
8
  */
9
9
  export declare function $initializeAboutCommand(program: Program): void;
10
10
  /**
11
- * TODO: !!! Test this in `deno`
12
11
  * TODO: [🗽] Unite branding and make single place for it
13
12
  * Note: [💞] Ignore a discrepancy between file name and entity name
14
13
  * Note: [🟡] Code in this file should never be published outside of `@promptbook/cli`
@@ -6,7 +6,7 @@ import type { PipelineCollection } from '../PipelineCollection';
6
6
  /**
7
7
  * Options for `createCollectionFromDirectory` function
8
8
  *
9
- * Note: `rootDirname` is not needed because it is the folder in which `.book.md` file is located
9
+ * Note: `rootDirname` is not needed because it is the folder in which `.book` or `.book.md` file is located
10
10
  * This is not same as `path` which is the first argument of `createCollectionFromDirectory` - it can be a subfolder
11
11
  */
12
12
  type CreatePipelineCollectionFromDirectoryOptions = Omit<PrepareAndScrapeOptions, 'rootDirname'> & {
@@ -51,13 +51,13 @@ type CreatePipelineCollectionFromDirectoryOptions = Omit<PrepareAndScrapeOptions
51
51
  *
52
52
  * Note: Works only in Node.js environment because it reads the file system
53
53
  *
54
- * @param path - path to the directory with pipelines
54
+ * @param rootPath - path to the directory with pipelines
55
55
  * @param tools - Execution tools to be used for pipeline preparation if needed - If not provided, `$provideExecutionToolsForNode` will be used
56
56
  * @param options - Options for the collection creation
57
57
  * @returns PipelineCollection
58
58
  * @public exported from `@promptbook/node`
59
59
  */
60
- export declare function createCollectionFromDirectory(path: string_dirname, tools?: Pick<ExecutionTools, 'llm' | 'fs' | 'scrapers'>, options?: CreatePipelineCollectionFromDirectoryOptions): Promise<PipelineCollection>;
60
+ export declare function createCollectionFromDirectory(rootPath: string_dirname, tools?: Pick<ExecutionTools, 'llm' | 'fs' | 'scrapers'>, options?: CreatePipelineCollectionFromDirectoryOptions): Promise<PipelineCollection>;
61
61
  export {};
62
62
  /**
63
63
  * TODO: [🖇] What about symlinks? Maybe option isSymlinksFollowed
@@ -11,8 +11,7 @@ import type { RemoteServerOptions } from './types/RemoteServerOptions';
11
11
  */
12
12
  export declare function startRemoteServer<TCustomOptions = undefined>(options: RemoteServerOptions<TCustomOptions>): IDestroyable;
13
13
  /**
14
- * TODO: !!!!!!! CORS and security
15
- * TODO: !!!!!!! Allow to pass tokem here
14
+ * TODO: !! Add CORS and security - probbably via `helmet`
16
15
  * TODO: [👩🏾‍🤝‍🧑🏾] Allow to pass custom fetch function here - PromptbookFetch
17
16
  * TODO: Split this file into multiple functions - handler for each request
18
17
  * TODO: Maybe use `$exportJson`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/cli",
3
- "version": "0.85.0-8",
3
+ "version": "0.85.0",
4
4
  "description": "It's time for a paradigm shift. The future of software in plain English, French or Latin",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -42,7 +42,7 @@
42
42
  "bugs": {
43
43
  "url": "https://github.com/webgptorg/promptbook/issues"
44
44
  },
45
- "homepage": "https://www.npmjs.com/package/@promptbook/core",
45
+ "homepage": "https://ptbk.io/",
46
46
  "dependencies": {
47
47
  "@ai-sdk/deepseek": "^0.1.6",
48
48
  "@ai-sdk/google": "1.0.5",
package/umd/index.umd.js CHANGED
@@ -53,7 +53,7 @@
53
53
  * @generated
54
54
  * @see https://github.com/webgptorg/promptbook
55
55
  */
56
- var PROMPTBOOK_ENGINE_VERSION = '0.85.0-7';
56
+ var PROMPTBOOK_ENGINE_VERSION = '0.85.0-16';
57
57
  /**
58
58
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
59
59
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -543,7 +543,6 @@
543
543
  }); });
544
544
  }
545
545
  /**
546
- * TODO: !!! Test this in `deno`
547
546
  * TODO: [🗽] Unite branding and make single place for it
548
547
  * Note: [💞] Ignore a discrepancy between file name and entity name
549
548
  * Note: [🟡] Code in this file should never be published outside of `@promptbook/cli`
@@ -4070,57 +4069,6 @@
4070
4069
  return true;
4071
4070
  }
4072
4071
 
4073
- /**
4074
- * Checks if an URL is reserved for private networks or localhost.
4075
- *
4076
- * Note: There are two simmilar functions:
4077
- * - `isUrlOnPrivateNetwork` which tests full URL
4078
- * - `isHostnameOnPrivateNetwork` *(this one)* which tests just hostname
4079
- *
4080
- * @public exported from `@promptbook/utils`
4081
- */
4082
- function isHostnameOnPrivateNetwork(hostname) {
4083
- if (hostname === 'example.com' ||
4084
- hostname === 'localhost' ||
4085
- hostname.endsWith('.localhost') ||
4086
- hostname.endsWith('.local') ||
4087
- hostname.endsWith('.test') ||
4088
- hostname === '127.0.0.1' ||
4089
- hostname === '::1') {
4090
- return true;
4091
- }
4092
- if (hostname.includes(':')) {
4093
- // IPv6
4094
- var ipParts = hostname.split(':');
4095
- return ipParts[0] === 'fc00' || ipParts[0] === 'fd00' || ipParts[0] === 'fe80';
4096
- }
4097
- else {
4098
- // IPv4
4099
- var ipParts = hostname.split('.').map(function (part) { return Number.parseInt(part, 10); });
4100
- return (ipParts[0] === 10 ||
4101
- (ipParts[0] === 172 && ipParts[1] >= 16 && ipParts[1] <= 31) ||
4102
- (ipParts[0] === 192 && ipParts[1] === 168));
4103
- }
4104
- }
4105
-
4106
- /**
4107
- * Checks if an IP address or hostname is reserved for private networks or localhost.
4108
- *
4109
- * Note: There are two simmilar functions:
4110
- * - `isUrlOnPrivateNetwork` *(this one)* which tests full URL
4111
- * - `isHostnameOnPrivateNetwork` which tests just hostname
4112
- *
4113
- * @param {string} ipAddress - The IP address to check.
4114
- * @returns {boolean} Returns true if the IP address is reserved for private networks or localhost, otherwise false.
4115
- * @public exported from `@promptbook/utils`
4116
- */
4117
- function isUrlOnPrivateNetwork(url) {
4118
- if (typeof url === 'string') {
4119
- url = new URL(url);
4120
- }
4121
- return isHostnameOnPrivateNetwork(url.hostname);
4122
- }
4123
-
4124
4072
  /**
4125
4073
  * Tests if given string is valid pipeline URL URL.
4126
4074
  *
@@ -4134,16 +4082,19 @@
4134
4082
  if (!isValidUrl(url)) {
4135
4083
  return false;
4136
4084
  }
4137
- if (!url.startsWith('https://')) {
4085
+ if (!url.startsWith('https://') && !url.startsWith('http://') /* <- Note: [👣] */) {
4138
4086
  return false;
4139
4087
  }
4140
4088
  if (url.includes('#')) {
4141
4089
  // TODO: [🐠]
4142
4090
  return false;
4143
4091
  }
4092
+ /*
4093
+ Note: [👣][🧠] Is it secure to allow pipeline URLs on private and unsecured networks?
4144
4094
  if (isUrlOnPrivateNetwork(url)) {
4145
4095
  return false;
4146
4096
  }
4097
+ */
4147
4098
  return true;
4148
4099
  }
4149
4100
  /**
@@ -4930,18 +4881,16 @@
4930
4881
  */
4931
4882
  function createTask(options) {
4932
4883
  var taskType = options.taskType, taskProcessCallback = options.taskProcessCallback;
4933
- var taskId = "".concat(taskType.toLowerCase().substring(0, 4), "-").concat($randomToken(8 /* <- TODO: !!! To global config + Use Base58 to avoid simmilar char conflicts */));
4884
+ var taskId = "".concat(taskType.toLowerCase().substring(0, 4), "-").concat($randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */));
4934
4885
  var partialResultSubject = new rxjs.BehaviorSubject({});
4935
4886
  var finalResultPromise = /* not await */ taskProcessCallback(function (newOngoingResult) {
4936
4887
  partialResultSubject.next(newOngoingResult);
4937
4888
  });
4938
4889
  finalResultPromise
4939
4890
  .catch(function (error) {
4940
- // console.error('!!!!! Task failed:', error);
4941
4891
  partialResultSubject.error(error);
4942
4892
  })
4943
4893
  .then(function (value) {
4944
- // console.error('!!!!! Task finished:', value);
4945
4894
  if (value) {
4946
4895
  try {
4947
4896
  assertsTaskSuccessful(value);
@@ -4963,9 +4912,7 @@
4963
4912
  return [4 /*yield*/, finalResultPromise];
4964
4913
  case 1:
4965
4914
  finalResult = _b.sent();
4966
- console.error('!!!!! finalResult:', finalResult);
4967
4915
  if (isCrashedOnError) {
4968
- console.error('!!!!! isCrashedOnError:', finalResult);
4969
4916
  assertsTaskSuccessful(finalResult);
4970
4917
  }
4971
4918
  return [2 /*return*/, finalResult];
@@ -12044,13 +11991,13 @@
12044
11991
  *
12045
11992
  * Note: Works only in Node.js environment because it reads the file system
12046
11993
  *
12047
- * @param path - path to the directory with pipelines
11994
+ * @param rootPath - path to the directory with pipelines
12048
11995
  * @param tools - Execution tools to be used for pipeline preparation if needed - If not provided, `$provideExecutionToolsForNode` will be used
12049
11996
  * @param options - Options for the collection creation
12050
11997
  * @returns PipelineCollection
12051
11998
  * @public exported from `@promptbook/node`
12052
11999
  */
12053
- function createCollectionFromDirectory(path$1, tools, options) {
12000
+ function createCollectionFromDirectory(rootPath, tools, options) {
12054
12001
  return __awaiter(this, void 0, void 0, function () {
12055
12002
  var madeLibraryFilePath, _a, _b, isRecursive, _c, isVerbose, _d, isLazyLoaded, _e, isCrashedOnError, rootUrl, collection;
12056
12003
  var _this = this;
@@ -12067,7 +12014,7 @@
12067
12014
  throw new EnvironmentMismatchError('Can not create collection without filesystem tools');
12068
12015
  // <- TODO: [🧠] What is the best error type here`
12069
12016
  }
12070
- madeLibraryFilePath = path.join(path$1, "".concat(DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME
12017
+ madeLibraryFilePath = path.join(rootPath, "".concat(DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME
12071
12018
  // <- TODO: [🦒] Allow to override (pass different value into the function)
12072
12019
  , ".json"));
12073
12020
  return [4 /*yield*/, isFileExisting(madeLibraryFilePath, tools.fs)];
@@ -12086,18 +12033,18 @@
12086
12033
  switch (_b.label) {
12087
12034
  case 0:
12088
12035
  if (isVerbose) {
12089
- console.info(colors__default["default"].cyan("Creating pipeline collection from path ".concat(path$1.split('\\').join('/'))));
12036
+ console.info(colors__default["default"].cyan("Creating pipeline collection from path ".concat(rootPath.split('\\').join('/'))));
12090
12037
  }
12091
- return [4 /*yield*/, listAllFiles(path$1, isRecursive, tools.fs)];
12038
+ return [4 /*yield*/, listAllFiles(rootPath, isRecursive, tools.fs)];
12092
12039
  case 1:
12093
12040
  fileNames = _b.sent();
12094
- // Note: First load all .book.json and then .book.md files
12095
- // .book.json can be prepared so it is faster to load
12041
+ // Note: First load all `.book.json` and then `.book` / `.book.md` files
12042
+ // `.book.json` can be prepared so it is faster to load
12096
12043
  fileNames.sort(function (a, b) {
12097
- if (a.endsWith('.json') && b.endsWith('.md')) {
12044
+ if (a.endsWith('.json') && (b.endsWith('.book') || b.endsWith('.book.md'))) {
12098
12045
  return -1;
12099
12046
  }
12100
- if (a.endsWith('.md') && b.endsWith('.json')) {
12047
+ if ((a.endsWith('.book') || a.endsWith('.book.md')) && b.endsWith('.json')) {
12101
12048
  return 1;
12102
12049
  }
12103
12050
  return 0;
@@ -12114,7 +12061,7 @@
12114
12061
  case 1:
12115
12062
  _f.trys.push([1, 8, , 9]);
12116
12063
  pipeline = null;
12117
- if (!fileName.endsWith('.book.md')) return [3 /*break*/, 4];
12064
+ if (!(fileName.endsWith('.book') || fileName.endsWith('.book.md'))) return [3 /*break*/, 4];
12118
12065
  _c = validatePipelineString;
12119
12066
  return [4 /*yield*/, promises.readFile(fileName, 'utf-8')];
12120
12067
  case 2:
@@ -12146,7 +12093,8 @@
12146
12093
  if (pipeline !== null) {
12147
12094
  if (rootUrl !== undefined) {
12148
12095
  if (pipeline.pipelineUrl === undefined) {
12149
- pipelineUrl = rootUrl + '/' + fileName.split('\\').join('/');
12096
+ pipelineUrl = rootUrl + '/' + path.relative(rootPath, fileName).split('\\').join('/');
12097
+ // console.log({ pipelineUrl, rootPath, rootUrl, fileName });
12150
12098
  if (isVerbose) {
12151
12099
  console.info(colors__default["default"].yellow("Implicitly set pipeline URL to ".concat(pipelineUrl, " from ").concat(fileName
12152
12100
  .split('\\')
@@ -13806,6 +13754,57 @@
13806
13754
  .filter(function (part) { return part !== ''; })
13807
13755
  .join('/');
13808
13756
  var startupDate = new Date();
13757
+ function getExecutionToolsFromIdentification(identification) {
13758
+ return __awaiter(this, void 0, void 0, function () {
13759
+ var isAnonymous, llm, llmToolsConfiguration, appId, userId, customOptions, fs, executables, tools;
13760
+ var _a;
13761
+ return __generator(this, function (_b) {
13762
+ switch (_b.label) {
13763
+ case 0:
13764
+ if (identification === null || identification === undefined) {
13765
+ throw new Error("Identification is not provided");
13766
+ }
13767
+ isAnonymous = identification.isAnonymous;
13768
+ if (isAnonymous === true && !isAnonymousModeAllowed) {
13769
+ throw new PipelineExecutionError("Anonymous mode is not allowed"); // <- TODO: [main] !!3 Test
13770
+ }
13771
+ if (isAnonymous === false && !isApplicationModeAllowed) {
13772
+ throw new PipelineExecutionError("Application mode is not allowed"); // <- TODO: [main] !!3 Test
13773
+ }
13774
+ if (!(isAnonymous === true)) return [3 /*break*/, 1];
13775
+ llmToolsConfiguration = identification.llmToolsConfiguration;
13776
+ llm = createLlmToolsFromConfiguration(llmToolsConfiguration, { isVerbose: isVerbose });
13777
+ return [3 /*break*/, 4];
13778
+ case 1:
13779
+ if (!(isAnonymous === false && createLlmExecutionTools !== null)) return [3 /*break*/, 3];
13780
+ appId = identification.appId, userId = identification.userId, customOptions = identification.customOptions;
13781
+ return [4 /*yield*/, createLlmExecutionTools({
13782
+ appId: appId,
13783
+ userId: userId,
13784
+ customOptions: customOptions,
13785
+ })];
13786
+ case 2:
13787
+ llm = _b.sent();
13788
+ return [3 /*break*/, 4];
13789
+ case 3: throw new PipelineExecutionError("You must provide either llmToolsConfiguration or non-anonymous mode must be propperly configured");
13790
+ case 4:
13791
+ fs = $provideFilesystemForNode();
13792
+ return [4 /*yield*/, $provideExecutablesForNode()];
13793
+ case 5:
13794
+ executables = _b.sent();
13795
+ _a = {
13796
+ llm: llm,
13797
+ fs: fs
13798
+ };
13799
+ return [4 /*yield*/, $provideScrapersForNode({ fs: fs, llm: llm, executables: executables })];
13800
+ case 6:
13801
+ tools = (_a.scrapers = _b.sent(),
13802
+ _a);
13803
+ return [2 /*return*/, tools];
13804
+ }
13805
+ });
13806
+ });
13807
+ }
13809
13808
  var app = express__default["default"]();
13810
13809
  app.use(express__default["default"].json());
13811
13810
  app.use(function (request, response, next) {
@@ -13879,6 +13878,46 @@
13879
13878
  }
13880
13879
  });
13881
13880
  }); });
13881
+ // TODO: [🧠] Is it secure / good idea to expose source codes of hosted books
13882
+ app.get("".concat(rootPath, "/books/*"), function (request, response) { return __awaiter(_this, void 0, void 0, function () {
13883
+ var pipelines, fullUrl, pipelineUrl, pipeline, source, error_1;
13884
+ return __generator(this, function (_a) {
13885
+ switch (_a.label) {
13886
+ case 0:
13887
+ _a.trys.push([0, 3, , 4]);
13888
+ if (collection === null) {
13889
+ response.status(500).send('No collection nor books available');
13890
+ return [2 /*return*/];
13891
+ }
13892
+ return [4 /*yield*/, collection.listPipelines()];
13893
+ case 1:
13894
+ pipelines = _a.sent();
13895
+ fullUrl = request.protocol + '://' + request.get('host') + request.originalUrl;
13896
+ pipelineUrl = pipelines.find(function (pipelineUrl) { return pipelineUrl.endsWith(request.originalUrl); }) || fullUrl;
13897
+ return [4 /*yield*/, collection.getPipelineByUrl(pipelineUrl)];
13898
+ case 2:
13899
+ pipeline = _a.sent();
13900
+ source = pipeline.sources[0];
13901
+ if (source === undefined || source.type !== 'BOOK') {
13902
+ throw new Error('Pipeline source is not a book');
13903
+ }
13904
+ response
13905
+ .type('text/markdown')
13906
+ .send(source.content);
13907
+ return [3 /*break*/, 4];
13908
+ case 3:
13909
+ error_1 = _a.sent();
13910
+ if (!(error_1 instanceof Error)) {
13911
+ throw error_1;
13912
+ }
13913
+ response
13914
+ .status(404)
13915
+ .send({ error: serializeError(error_1) });
13916
+ return [3 /*break*/, 4];
13917
+ case 4: return [2 /*return*/];
13918
+ }
13919
+ });
13920
+ }); });
13882
13921
  app.get("".concat(rootPath, "/executions"), function (request, response) { return __awaiter(_this, void 0, void 0, function () {
13883
13922
  return __generator(this, function (_a) {
13884
13923
  response.send(runningExecutionTasks);
@@ -13891,7 +13930,9 @@
13891
13930
  taskId = request.params.taskId;
13892
13931
  execution = runningExecutionTasks.find(function (executionTask) { return executionTask.taskId === taskId; });
13893
13932
  if (execution === undefined) {
13894
- response.status(404).send("Execution \"".concat(taskId, "\" not found"));
13933
+ response
13934
+ .status(404)
13935
+ .send("Execution \"".concat(taskId, "\" not found"));
13895
13936
  return [2 /*return*/];
13896
13937
  }
13897
13938
  response.send(execution.currentValue);
@@ -13899,13 +13940,12 @@
13899
13940
  });
13900
13941
  }); });
13901
13942
  app.post("".concat(rootPath, "/executions/new"), function (request, response) { return __awaiter(_this, void 0, void 0, function () {
13902
- var inputParameters, pipelineUrl, pipeline, llm, fs, executables, tools, pipelineExecutor, executionTask, error_1;
13903
- var _a;
13943
+ var _a, inputParameters, identification, pipelineUrl, pipeline, tools, pipelineExecutor, executionTask, error_2;
13904
13944
  return __generator(this, function (_b) {
13905
13945
  switch (_b.label) {
13906
13946
  case 0:
13907
- _b.trys.push([0, 6, , 7]);
13908
- inputParameters = request.body.inputParameters;
13947
+ _b.trys.push([0, 4, , 5]);
13948
+ _a = request.body, inputParameters = _a.inputParameters, identification = _a.identification;
13909
13949
  pipelineUrl = request.body.pipelineUrl || request.body.book;
13910
13950
  return [4 /*yield*/, (collection === null || collection === void 0 ? void 0 : collection.getPipelineByUrl(pipelineUrl))];
13911
13951
  case 1:
@@ -13914,43 +13954,27 @@
13914
13954
  response.status(404).send("Pipeline \"".concat(pipelineUrl, "\" not found"));
13915
13955
  return [2 /*return*/];
13916
13956
  }
13917
- return [4 /*yield*/, createLlmExecutionTools({
13918
- appId: '!!!!',
13919
- userId: '!!!!',
13920
- customOptions: {},
13921
- })];
13957
+ return [4 /*yield*/, getExecutionToolsFromIdentification(identification)];
13922
13958
  case 2:
13923
- llm = _b.sent();
13924
- fs = $provideFilesystemForNode();
13925
- return [4 /*yield*/, $provideExecutablesForNode()];
13926
- case 3:
13927
- executables = _b.sent();
13928
- _a = {
13929
- llm: llm,
13930
- fs: fs
13931
- };
13932
- return [4 /*yield*/, $provideScrapersForNode({ fs: fs, llm: llm, executables: executables })];
13933
- case 4:
13934
- tools = (_a.scrapers = _b.sent(),
13935
- _a);
13959
+ tools = _b.sent();
13936
13960
  pipelineExecutor = createPipelineExecutor(__assign({ pipeline: pipeline, tools: tools }, options));
13937
13961
  executionTask = pipelineExecutor(inputParameters);
13938
13962
  runningExecutionTasks.push(executionTask);
13939
13963
  return [4 /*yield*/, waitasecond.forTime(10)];
13940
- case 5:
13964
+ case 3:
13941
13965
  _b.sent();
13942
13966
  // <- Note: Wait for a while to wait for quick responses or sudden but asynchronous errors
13943
13967
  // <- TODO: Put this into configuration
13944
13968
  response.send(executionTask);
13945
- return [3 /*break*/, 7];
13946
- case 6:
13947
- error_1 = _b.sent();
13948
- if (!(error_1 instanceof Error)) {
13949
- throw error_1;
13969
+ return [3 /*break*/, 5];
13970
+ case 4:
13971
+ error_2 = _b.sent();
13972
+ if (!(error_2 instanceof Error)) {
13973
+ throw error_2;
13950
13974
  }
13951
- response.status(400).send({ error: serializeError(error_1) });
13952
- return [3 /*break*/, 7];
13953
- case 7: return [2 /*return*/];
13975
+ response.status(400).send({ error: serializeError(error_2) });
13976
+ return [3 /*break*/, 5];
13977
+ case 5: return [2 /*return*/];
13954
13978
  }
13955
13979
  });
13956
13980
  }); });
@@ -13967,55 +13991,9 @@
13967
13991
  if (isVerbose) {
13968
13992
  console.info(colors__default["default"].gray("Client connected"), socket.id);
13969
13993
  }
13970
- var getExecutionToolsFromIdentification = function (identification) { return __awaiter(_this, void 0, void 0, function () {
13971
- var isAnonymous, llm, llmToolsConfiguration, appId, userId, customOptions, fs, executables, tools;
13972
- var _a;
13973
- return __generator(this, function (_b) {
13974
- switch (_b.label) {
13975
- case 0:
13976
- isAnonymous = identification.isAnonymous;
13977
- if (isAnonymous === true && !isAnonymousModeAllowed) {
13978
- throw new PipelineExecutionError("Anonymous mode is not allowed"); // <- TODO: [main] !!3 Test
13979
- }
13980
- if (isAnonymous === false && !isApplicationModeAllowed) {
13981
- throw new PipelineExecutionError("Application mode is not allowed"); // <- TODO: [main] !!3 Test
13982
- }
13983
- if (!(isAnonymous === true)) return [3 /*break*/, 1];
13984
- llmToolsConfiguration = identification.llmToolsConfiguration;
13985
- llm = createLlmToolsFromConfiguration(llmToolsConfiguration, { isVerbose: isVerbose });
13986
- return [3 /*break*/, 4];
13987
- case 1:
13988
- if (!(isAnonymous === false && createLlmExecutionTools !== null)) return [3 /*break*/, 3];
13989
- appId = identification.appId, userId = identification.userId, customOptions = identification.customOptions;
13990
- return [4 /*yield*/, createLlmExecutionTools({
13991
- appId: appId,
13992
- userId: userId,
13993
- customOptions: customOptions,
13994
- })];
13995
- case 2:
13996
- llm = _b.sent();
13997
- return [3 /*break*/, 4];
13998
- case 3: throw new PipelineExecutionError("You must provide either llmToolsConfiguration or non-anonymous mode must be propperly configured");
13999
- case 4:
14000
- fs = $provideFilesystemForNode();
14001
- return [4 /*yield*/, $provideExecutablesForNode()];
14002
- case 5:
14003
- executables = _b.sent();
14004
- _a = {
14005
- llm: llm,
14006
- fs: fs
14007
- };
14008
- return [4 /*yield*/, $provideScrapersForNode({ fs: fs, llm: llm, executables: executables })];
14009
- case 6:
14010
- tools = (_a.scrapers = _b.sent(),
14011
- _a);
14012
- return [2 /*return*/, tools];
14013
- }
14014
- });
14015
- }); };
14016
13994
  // -----------
14017
13995
  socket.on('prompt-request', function (request) { return __awaiter(_this, void 0, void 0, function () {
14018
- var identification, prompt, executionTools, llm, _a, promptResult, _b, error_2;
13996
+ var identification, prompt, tools, llm, _a, promptResult, _b, error_3;
14019
13997
  return __generator(this, function (_c) {
14020
13998
  switch (_c.label) {
14021
13999
  case 0:
@@ -14028,8 +14006,8 @@
14028
14006
  _c.trys.push([1, 13, 14, 15]);
14029
14007
  return [4 /*yield*/, getExecutionToolsFromIdentification(identification)];
14030
14008
  case 2:
14031
- executionTools = _c.sent();
14032
- llm = executionTools.llm;
14009
+ tools = _c.sent();
14010
+ llm = tools.llm;
14033
14011
  _a = identification.isAnonymous === false &&
14034
14012
  collection !== null;
14035
14013
  if (!_a) return [3 /*break*/, 4];
@@ -14084,11 +14062,11 @@
14084
14062
  socket.emit('prompt-response', { promptResult: promptResult } /* <- Note: [🤛] */);
14085
14063
  return [3 /*break*/, 15];
14086
14064
  case 13:
14087
- error_2 = _c.sent();
14088
- if (!(error_2 instanceof Error)) {
14089
- throw error_2;
14065
+ error_3 = _c.sent();
14066
+ if (!(error_3 instanceof Error)) {
14067
+ throw error_3;
14090
14068
  }
14091
- socket.emit('error', serializeError(error_2) /* <- Note: [🤛] */);
14069
+ socket.emit('error', serializeError(error_3) /* <- Note: [🤛] */);
14092
14070
  return [3 /*break*/, 15];
14093
14071
  case 14:
14094
14072
  socket.disconnect();
@@ -14100,7 +14078,7 @@
14100
14078
  // -----------
14101
14079
  // TODO: [👒] Listing models (and checking configuration) probbably should go through REST API not Socket.io
14102
14080
  socket.on('listModels-request', function (request) { return __awaiter(_this, void 0, void 0, function () {
14103
- var identification, executionTools, llm, models, error_3;
14081
+ var identification, tools, llm, models, error_4;
14104
14082
  return __generator(this, function (_a) {
14105
14083
  switch (_a.label) {
14106
14084
  case 0:
@@ -14113,19 +14091,19 @@
14113
14091
  _a.trys.push([1, 4, 5, 6]);
14114
14092
  return [4 /*yield*/, getExecutionToolsFromIdentification(identification)];
14115
14093
  case 2:
14116
- executionTools = _a.sent();
14117
- llm = executionTools.llm;
14094
+ tools = _a.sent();
14095
+ llm = tools.llm;
14118
14096
  return [4 /*yield*/, llm.listModels()];
14119
14097
  case 3:
14120
14098
  models = _a.sent();
14121
14099
  socket.emit('listModels-response', { models: models } /* <- Note: [🤛] */);
14122
14100
  return [3 /*break*/, 6];
14123
14101
  case 4:
14124
- error_3 = _a.sent();
14125
- if (!(error_3 instanceof Error)) {
14126
- throw error_3;
14102
+ error_4 = _a.sent();
14103
+ if (!(error_4 instanceof Error)) {
14104
+ throw error_4;
14127
14105
  }
14128
- socket.emit('error', serializeError(error_3));
14106
+ socket.emit('error', serializeError(error_4));
14129
14107
  return [3 /*break*/, 6];
14130
14108
  case 5:
14131
14109
  socket.disconnect();
@@ -14137,7 +14115,7 @@
14137
14115
  // -----------
14138
14116
  // TODO: [👒] Listing models (and checking configuration) probbably should go through REST API not Socket.io
14139
14117
  socket.on('preparePipeline-request', function (request) { return __awaiter(_this, void 0, void 0, function () {
14140
- var identification, pipeline, executionTools, preparedPipeline, error_4;
14118
+ var identification, pipeline, tools, preparedPipeline, error_5;
14141
14119
  return __generator(this, function (_a) {
14142
14120
  switch (_a.label) {
14143
14121
  case 0:
@@ -14150,18 +14128,18 @@
14150
14128
  _a.trys.push([1, 4, 5, 6]);
14151
14129
  return [4 /*yield*/, getExecutionToolsFromIdentification(identification)];
14152
14130
  case 2:
14153
- executionTools = _a.sent();
14154
- return [4 /*yield*/, preparePipeline(pipeline, executionTools, options)];
14131
+ tools = _a.sent();
14132
+ return [4 /*yield*/, preparePipeline(pipeline, tools, options)];
14155
14133
  case 3:
14156
14134
  preparedPipeline = _a.sent();
14157
14135
  socket.emit('preparePipeline-response', { preparedPipeline: preparedPipeline } /* <- Note: [🤛] */);
14158
14136
  return [3 /*break*/, 6];
14159
14137
  case 4:
14160
- error_4 = _a.sent();
14161
- if (!(error_4 instanceof Error)) {
14162
- throw error_4;
14138
+ error_5 = _a.sent();
14139
+ if (!(error_5 instanceof Error)) {
14140
+ throw error_5;
14163
14141
  }
14164
- socket.emit('error', serializeError(error_4));
14142
+ socket.emit('error', serializeError(error_5));
14165
14143
  return [3 /*break*/, 6];
14166
14144
  case 5:
14167
14145
  socket.disconnect();
@@ -14200,8 +14178,7 @@
14200
14178
  };
14201
14179
  }
14202
14180
  /**
14203
- * TODO: !!!!!!! CORS and security
14204
- * TODO: !!!!!!! Allow to pass tokem here
14181
+ * TODO: !! Add CORS and security - probbably via `helmet`
14205
14182
  * TODO: [👩🏾‍🤝‍🧑🏾] Allow to pass custom fetch function here - PromptbookFetch
14206
14183
  * TODO: Split this file into multiple functions - handler for each request
14207
14184
  * TODO: Maybe use `$exportJson`
@@ -15540,7 +15517,7 @@
15540
15517
  pricing: {
15541
15518
  prompt: computeUsage("$3.00 / 1M tokens"),
15542
15519
  output: computeUsage("$12.00 / 1M tokens"),
15543
- // <- TODO: !!! Unsure, check the pricing
15520
+ // <- TODO: !! Unsure, check the pricing
15544
15521
  },
15545
15522
  },
15546
15523
  /**/
@@ -15552,7 +15529,7 @@
15552
15529
  pricing: {
15553
15530
  prompt: computeUsage("$3.00 / 1M tokens"),
15554
15531
  output: computeUsage("$12.00 / 1M tokens"),
15555
- // <- TODO: !!! Unsure, check the pricing
15532
+ // <- TODO: !! Unsure, check the pricing
15556
15533
  },
15557
15534
  },
15558
15535
  /**/