@promptbook/remote-server 0.85.0-1 → 0.85.0-10

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.
@@ -47,6 +47,7 @@ import { parseKeywords } from '../utils/normalization/parseKeywords';
47
47
  import { parseKeywordsFromString } from '../utils/normalization/parseKeywordsFromString';
48
48
  import { removeDiacritics } from '../utils/normalization/removeDiacritics';
49
49
  import { searchKeywords } from '../utils/normalization/searchKeywords';
50
+ import { suffixUrl } from '../utils/normalization/suffixUrl';
50
51
  import { titleToName } from '../utils/normalization/titleToName';
51
52
  import { spaceTrim } from '../utils/organization/spaceTrim';
52
53
  import { extractParameterNames } from '../utils/parameters/extractParameterNames';
@@ -128,6 +129,7 @@ export { parseKeywords };
128
129
  export { parseKeywordsFromString };
129
130
  export { removeDiacritics };
130
131
  export { searchKeywords };
132
+ export { suffixUrl };
131
133
  export { titleToName };
132
134
  export { spaceTrim };
133
135
  export { extractParameterNames };
@@ -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`
@@ -1,7 +1,7 @@
1
1
  import type { Observable } from 'rxjs';
2
2
  import { PartialDeep } from 'type-fest';
3
- import type { string_SCREAMING_CASE } from '../utils/normalization/normalizeTo_SCREAMING_CASE';
4
3
  import type { task_id } from '../types/typeAliases';
4
+ import type { string_SCREAMING_CASE } from '../utils/normalization/normalizeTo_SCREAMING_CASE';
5
5
  import type { AbstractTaskResult } from './AbstractTaskResult';
6
6
  import type { PipelineExecutorResult } from './PipelineExecutorResult';
7
7
  /**
@@ -30,7 +30,7 @@ export declare function createTask<TTaskResult extends AbstractTaskResult>(optio
30
30
  */
31
31
  export type ExecutionTask = AbstractTask<PipelineExecutorResult> & {
32
32
  readonly taskType: 'EXECUTION';
33
- readonly taskId: `execution-${task_id}`;
33
+ readonly taskId: `exec-${task_id}`;
34
34
  };
35
35
  /**
36
36
  * Represents a task that prepares a pipeline
@@ -38,7 +38,7 @@ export type ExecutionTask = AbstractTask<PipelineExecutorResult> & {
38
38
  */
39
39
  export type PreparationTask = AbstractTask<PipelineExecutorResult> & {
40
40
  readonly taskType: 'PREPARATION';
41
- readonly taskId: `preparation-${task_id}`;
41
+ readonly taskId: `prep-${task_id}`;
42
42
  };
43
43
  /**
44
44
  * Base interface for all task types
@@ -62,6 +62,10 @@ export type AbstractTask<TTaskResult extends AbstractTaskResult> = {
62
62
  * Gets an observable stream of partial task results
63
63
  */
64
64
  asObservable(): Observable<PartialDeep<TTaskResult>>;
65
+ /**
66
+ * Gets just the current value which is mutated during the task processing
67
+ */
68
+ currentValue: PartialDeep<TTaskResult>;
65
69
  };
66
70
  export type Task = ExecutionTask | PreparationTask;
67
71
  export {};
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import type fs from 'node:fs/promises';
2
+ import type fs from 'fs/promises';
3
3
  /**
4
4
  * Container for all the tools needed to manipulate with filesystem
5
5
  */
@@ -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`
@@ -0,0 +1,7 @@
1
+ import type { string_url } from '../../types/typeAliases';
2
+ /**
3
+ * Adds suffix to the URL
4
+ *
5
+ * @public exported from `@promptbook/utils`
6
+ */
7
+ export declare function suffixUrl(value: URL, suffix: `/${string}`): string_url;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/remote-server",
3
- "version": "0.85.0-1",
3
+ "version": "0.85.0-10",
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,
@@ -47,7 +47,7 @@
47
47
  "module": "./esm/index.es.js",
48
48
  "typings": "./esm/typings/src/_packages/remote-server.index.d.ts",
49
49
  "peerDependencies": {
50
- "@promptbook/core": "0.85.0-1"
50
+ "@promptbook/core": "0.85.0-10"
51
51
  },
52
52
  "dependencies": {
53
53
  "colors": "1.4.0",
package/umd/index.umd.js CHANGED
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('express'), require('node:http'), require('socket.io'), require('spacetrim'), require('node:child_process'), require('waitasecond'), require('node:fs/promises'), require('node:path'), require('rxjs'), require('crypto'), require('prettier'), require('prettier/parser-html'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('crypto-js'), require('mime-types'), require('papaparse')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'colors', 'express', 'node:http', 'socket.io', 'spacetrim', 'node:child_process', 'waitasecond', 'node:fs/promises', 'node:path', 'rxjs', 'crypto', 'prettier', 'prettier/parser-html', 'crypto-js/enc-hex', 'crypto-js/sha256', 'crypto-js', 'mime-types', 'papaparse'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-remote-server"] = {}, global.colors, global.express, global.http, global.socket_io, global.spaceTrim, global.node_child_process, global.waitasecond, global.promises, global.node_path, global.rxjs, global.crypto, global.prettier, global.parserHtml, global.hexEncoder, global.sha256, global.cryptoJs, global.mimeTypes, global.papaparse));
5
- })(this, (function (exports, colors, express, http, socket_io, spaceTrim, node_child_process, waitasecond, promises, node_path, rxjs, crypto, prettier, parserHtml, hexEncoder, sha256, cryptoJs, mimeTypes, papaparse) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('express'), require('http'), require('socket.io'), require('spacetrim'), require('waitasecond'), require('child_process'), require('fs/promises'), require('path'), require('rxjs'), require('crypto'), require('prettier'), require('prettier/parser-html'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('crypto-js'), require('mime-types'), require('papaparse')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'colors', 'express', 'http', 'socket.io', 'spacetrim', 'waitasecond', 'child_process', 'fs/promises', 'path', 'rxjs', 'crypto', 'prettier', 'prettier/parser-html', 'crypto-js/enc-hex', 'crypto-js/sha256', 'crypto-js', 'mime-types', 'papaparse'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-remote-server"] = {}, global.colors, global.express, global.http, global.socket_io, global.spaceTrim, global.waitasecond, global.child_process, global.promises, global.path, global.rxjs, global.crypto, global.prettier, global.parserHtml, global.hexEncoder, global.sha256, global.cryptoJs, global.mimeTypes, global.papaparse));
5
+ })(this, (function (exports, colors, express, http, socket_io, spaceTrim, waitasecond, child_process, promises, path, rxjs, crypto, prettier, parserHtml, hexEncoder, sha256, cryptoJs, mimeTypes, papaparse) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -28,7 +28,7 @@
28
28
  * @generated
29
29
  * @see https://github.com/webgptorg/promptbook
30
30
  */
31
- var PROMPTBOOK_ENGINE_VERSION = '0.85.0-0';
31
+ var PROMPTBOOK_ENGINE_VERSION = '0.85.0-9';
32
32
  /**
33
33
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
34
34
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -777,7 +777,7 @@
777
777
  console.info(colors__default["default"].yellow(cwd) + ' ' + colors__default["default"].green(command) + ' ' + colors__default["default"].blue(args.join(' ')));
778
778
  }
779
779
  try {
780
- var commandProcess = node_child_process.spawn(command, args, { cwd: cwd, shell: true });
780
+ var commandProcess = child_process.spawn(command, args, { cwd: cwd, shell: true });
781
781
  if (isVerbose) {
782
782
  commandProcess.on('message', function (message) {
783
783
  console.info({ message: message });
@@ -987,7 +987,7 @@
987
987
  function locateAppOnWindows(_a) {
988
988
  var appName = _a.appName, windowsSuffix = _a.windowsSuffix;
989
989
  return __awaiter(this, void 0, void 0, function () {
990
- var prefixes, prefixes_1, prefixes_1_1, prefix, path, e_1_1, error_1;
990
+ var prefixes, prefixes_1, prefixes_1_1, prefix, path$1, e_1_1, error_1;
991
991
  var e_1, _b;
992
992
  return __generator(this, function (_c) {
993
993
  switch (_c.label) {
@@ -995,7 +995,7 @@
995
995
  _c.trys.push([0, 9, , 10]);
996
996
  prefixes = [
997
997
  process.env.LOCALAPPDATA,
998
- node_path.join(process.env.LOCALAPPDATA || '', 'Programs'),
998
+ path.join(process.env.LOCALAPPDATA || '', 'Programs'),
999
999
  process.env.PROGRAMFILES,
1000
1000
  process.env['PROGRAMFILES(X86)'],
1001
1001
  ];
@@ -1007,11 +1007,11 @@
1007
1007
  case 2:
1008
1008
  if (!!prefixes_1_1.done) return [3 /*break*/, 5];
1009
1009
  prefix = prefixes_1_1.value;
1010
- path = prefix + windowsSuffix;
1011
- return [4 /*yield*/, isExecutable(path, $provideFilesystemForNode())];
1010
+ path$1 = prefix + windowsSuffix;
1011
+ return [4 /*yield*/, isExecutable(path$1, $provideFilesystemForNode())];
1012
1012
  case 3:
1013
1013
  if (_c.sent()) {
1014
- return [2 /*return*/, path];
1014
+ return [2 /*return*/, path$1];
1015
1015
  }
1016
1016
  _c.label = 4;
1017
1017
  case 4:
@@ -2006,11 +2006,27 @@
2006
2006
  */
2007
2007
  function createTask(options) {
2008
2008
  var taskType = options.taskType, taskProcessCallback = options.taskProcessCallback;
2009
- var taskId = "".concat(taskType.toLowerCase(), "-").concat($randomToken(256 /* <- TODO: !!! To global config */));
2009
+ var taskId = "".concat(taskType.toLowerCase().substring(0, 4), "-").concat($randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */));
2010
2010
  var partialResultSubject = new rxjs.BehaviorSubject({});
2011
2011
  var finalResultPromise = /* not await */ taskProcessCallback(function (newOngoingResult) {
2012
2012
  partialResultSubject.next(newOngoingResult);
2013
2013
  });
2014
+ finalResultPromise
2015
+ .catch(function (error) {
2016
+ partialResultSubject.error(error);
2017
+ })
2018
+ .then(function (value) {
2019
+ if (value) {
2020
+ try {
2021
+ assertsTaskSuccessful(value);
2022
+ partialResultSubject.next(value);
2023
+ }
2024
+ catch (error) {
2025
+ partialResultSubject.error(error);
2026
+ }
2027
+ }
2028
+ partialResultSubject.complete();
2029
+ });
2014
2030
  function asPromise(options) {
2015
2031
  return __awaiter(this, void 0, void 0, function () {
2016
2032
  var _a, isCrashedOnError, finalResult;
@@ -2034,9 +2050,10 @@
2034
2050
  taskId: taskId,
2035
2051
  asPromise: asPromise,
2036
2052
  asObservable: function () {
2037
- return rxjs.concat(partialResultSubject.asObservable(), rxjs.from(asPromise({
2038
- isCrashedOnError: true,
2039
- })));
2053
+ return partialResultSubject.asObservable();
2054
+ },
2055
+ get currentValue() {
2056
+ return partialResultSubject.value;
2040
2057
  },
2041
2058
  };
2042
2059
  }
@@ -3979,7 +3996,7 @@
3979
3996
  value = value.replace(/\.html$/, '');
3980
3997
  }
3981
3998
  else if (isValidFilePath(value)) {
3982
- value = node_path.basename(value);
3999
+ value = path.basename(value);
3983
4000
  // Note: Keeping extension in the name
3984
4001
  }
3985
4002
  value = value.split('/').join('-');
@@ -4085,9 +4102,9 @@
4085
4102
  }
4086
4103
  basename = url.split('/').pop() || titleToName(url);
4087
4104
  hash = sha256__default["default"](hexEncoder__default["default"].parse(url)).toString( /* hex */);
4088
- rootDirname_1 = node_path.join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
4089
- filepath = node_path.join.apply(void 0, __spreadArray(__spreadArray([], __read(nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */)), false), ["".concat(basename.substring(0, MAX_FILENAME_LENGTH), ".").concat(mimeTypeToExtension(mimeType))], false));
4090
- return [4 /*yield*/, tools.fs.mkdir(node_path.dirname(node_path.join(rootDirname_1, filepath)), { recursive: true })];
4105
+ rootDirname_1 = path.join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
4106
+ filepath = path.join.apply(void 0, __spreadArray(__spreadArray([], __read(nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */)), false), ["".concat(basename.substring(0, MAX_FILENAME_LENGTH), ".").concat(mimeTypeToExtension(mimeType))], false));
4107
+ return [4 /*yield*/, tools.fs.mkdir(path.dirname(path.join(rootDirname_1, filepath)), { recursive: true })];
4091
4108
  case 2:
4092
4109
  _h.sent();
4093
4110
  _g = (_f = Buffer).from;
@@ -4097,7 +4114,7 @@
4097
4114
  if (fileContent.length > DEFAULT_MAX_FILE_SIZE /* <- TODO: Allow to pass different value to remote server */) {
4098
4115
  throw new LimitReachedError("File is too large (".concat(Math.round(fileContent.length / 1024 / 1024), "MB). Maximum allowed size is ").concat(Math.round(DEFAULT_MAX_FILE_SIZE / 1024 / 1024), "MB."));
4099
4116
  }
4100
- return [4 /*yield*/, tools.fs.writeFile(node_path.join(rootDirname_1, filepath), fileContent)];
4117
+ return [4 /*yield*/, tools.fs.writeFile(path.join(rootDirname_1, filepath), fileContent)];
4101
4118
  case 4:
4102
4119
  _h.sent();
4103
4120
  // TODO: [💵] Check the file security
@@ -4113,7 +4130,7 @@
4113
4130
  throw new EnvironmentMismatchError('Can not import file knowledge in non-file pipeline');
4114
4131
  // <- TODO: [🧠] What is the best error type here`
4115
4132
  }
4116
- filename_1 = node_path.join(rootDirname, knowledgeSourceContent).split('\\').join('/');
4133
+ filename_1 = path.join(rootDirname, knowledgeSourceContent).split('\\').join('/');
4117
4134
  fileExtension = getFileExtension(filename_1);
4118
4135
  mimeType = extensionToMimeType(fileExtension || '');
4119
4136
  return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
@@ -6873,6 +6890,57 @@
6873
6890
  .filter(function (part) { return part !== ''; })
6874
6891
  .join('/');
6875
6892
  var startupDate = new Date();
6893
+ function getExecutionToolsFromIdentification(identification) {
6894
+ return __awaiter(this, void 0, void 0, function () {
6895
+ var isAnonymous, llm, llmToolsConfiguration, appId, userId, customOptions, fs, executables, tools;
6896
+ var _a;
6897
+ return __generator(this, function (_b) {
6898
+ switch (_b.label) {
6899
+ case 0:
6900
+ if (identification === null || identification === undefined) {
6901
+ throw new Error("Identification is not provided");
6902
+ }
6903
+ isAnonymous = identification.isAnonymous;
6904
+ if (isAnonymous === true && !isAnonymousModeAllowed) {
6905
+ throw new PipelineExecutionError("Anonymous mode is not allowed"); // <- TODO: [main] !!3 Test
6906
+ }
6907
+ if (isAnonymous === false && !isApplicationModeAllowed) {
6908
+ throw new PipelineExecutionError("Application mode is not allowed"); // <- TODO: [main] !!3 Test
6909
+ }
6910
+ if (!(isAnonymous === true)) return [3 /*break*/, 1];
6911
+ llmToolsConfiguration = identification.llmToolsConfiguration;
6912
+ llm = createLlmToolsFromConfiguration(llmToolsConfiguration, { isVerbose: isVerbose });
6913
+ return [3 /*break*/, 4];
6914
+ case 1:
6915
+ if (!(isAnonymous === false && createLlmExecutionTools !== null)) return [3 /*break*/, 3];
6916
+ appId = identification.appId, userId = identification.userId, customOptions = identification.customOptions;
6917
+ return [4 /*yield*/, createLlmExecutionTools({
6918
+ appId: appId,
6919
+ userId: userId,
6920
+ customOptions: customOptions,
6921
+ })];
6922
+ case 2:
6923
+ llm = _b.sent();
6924
+ return [3 /*break*/, 4];
6925
+ case 3: throw new PipelineExecutionError("You must provide either llmToolsConfiguration or non-anonymous mode must be propperly configured");
6926
+ case 4:
6927
+ fs = $provideFilesystemForNode();
6928
+ return [4 /*yield*/, $provideExecutablesForNode()];
6929
+ case 5:
6930
+ executables = _b.sent();
6931
+ _a = {
6932
+ llm: llm,
6933
+ fs: fs
6934
+ };
6935
+ return [4 /*yield*/, $provideScrapersForNode({ fs: fs, llm: llm, executables: executables })];
6936
+ case 6:
6937
+ tools = (_a.scrapers = _b.sent(),
6938
+ _a);
6939
+ return [2 /*return*/, tools];
6940
+ }
6941
+ });
6942
+ });
6943
+ }
6876
6944
  var app = express__default["default"]();
6877
6945
  app.use(express__default["default"].json());
6878
6946
  app.use(function (request, response, next) {
@@ -6880,7 +6948,7 @@
6880
6948
  next();
6881
6949
  });
6882
6950
  var runningExecutionTasks = [];
6883
- // TODO: !!!!!! Do here some garbage collection of finished tasks
6951
+ // TODO: [🧠] Do here some garbage collection of finished tasks
6884
6952
  app.get(['/', rootPath], function (request, response) { return __awaiter(_this, void 0, void 0, function () {
6885
6953
  var _a, _b;
6886
6954
  var _this = this;
@@ -6929,20 +6997,19 @@
6929
6997
  });
6930
6998
  }); });
6931
6999
  app.get("".concat(rootPath, "/books"), function (request, response) { return __awaiter(_this, void 0, void 0, function () {
6932
- var _a, _b, _c;
6933
- return __generator(this, function (_d) {
6934
- switch (_d.label) {
7000
+ var pipelines;
7001
+ return __generator(this, function (_a) {
7002
+ switch (_a.label) {
6935
7003
  case 0:
6936
- _b = (_a = response).send;
6937
- if (!(collection === null)) return [3 /*break*/, 1];
6938
- _c = [];
6939
- return [3 /*break*/, 3];
6940
- case 1: return [4 /*yield*/, collection.listPipelines()];
6941
- case 2:
6942
- _c = _d.sent();
6943
- _d.label = 3;
6944
- case 3:
6945
- _b.apply(_a, [_c]);
7004
+ if (collection === null) {
7005
+ response.status(500).send('No collection available');
7006
+ return [2 /*return*/];
7007
+ }
7008
+ return [4 /*yield*/, collection.listPipelines()];
7009
+ case 1:
7010
+ pipelines = _a.sent();
7011
+ // <- TODO: [🧠][👩🏾‍🤝‍🧑🏿] List `inputParameters` required for the execution
7012
+ response.send(pipelines);
6946
7013
  return [2 /*return*/];
6947
7014
  }
6948
7015
  });
@@ -6956,23 +7023,23 @@
6956
7023
  app.get("".concat(rootPath, "/executions/:taskId"), function (request, response) { return __awaiter(_this, void 0, void 0, function () {
6957
7024
  var taskId, execution;
6958
7025
  return __generator(this, function (_a) {
6959
- taskId = request.query.taskId;
7026
+ taskId = request.params.taskId;
6960
7027
  execution = runningExecutionTasks.find(function (executionTask) { return executionTask.taskId === taskId; });
6961
7028
  if (execution === undefined) {
6962
7029
  response.status(404).send("Execution \"".concat(taskId, "\" not found"));
6963
7030
  return [2 /*return*/];
6964
7031
  }
6965
- response.send(execution);
7032
+ response.send(execution.currentValue);
6966
7033
  return [2 /*return*/];
6967
7034
  });
6968
7035
  }); });
6969
7036
  app.post("".concat(rootPath, "/executions/new"), function (request, response) { return __awaiter(_this, void 0, void 0, function () {
6970
- var inputParameters, pipelineUrl, pipeline, llm, fs, executables, tools, pipelineExecutor, executionTask;
6971
- var _a;
7037
+ var _a, inputParameters, identification, pipelineUrl, pipeline, tools, pipelineExecutor, executionTask, error_1;
6972
7038
  return __generator(this, function (_b) {
6973
7039
  switch (_b.label) {
6974
7040
  case 0:
6975
- inputParameters = request.body.inputParameters;
7041
+ _b.trys.push([0, 4, , 5]);
7042
+ _a = request.body, inputParameters = _a.inputParameters, identification = _a.identification;
6976
7043
  pipelineUrl = request.body.pipelineUrl || request.body.book;
6977
7044
  return [4 /*yield*/, (collection === null || collection === void 0 ? void 0 : collection.getPipelineByUrl(pipelineUrl))];
6978
7045
  case 1:
@@ -6981,30 +7048,27 @@
6981
7048
  response.status(404).send("Pipeline \"".concat(pipelineUrl, "\" not found"));
6982
7049
  return [2 /*return*/];
6983
7050
  }
6984
- return [4 /*yield*/, createLlmExecutionTools({
6985
- appId: '!!!!',
6986
- userId: '!!!!',
6987
- customOptions: {},
6988
- })];
7051
+ return [4 /*yield*/, getExecutionToolsFromIdentification(identification)];
6989
7052
  case 2:
6990
- llm = _b.sent();
6991
- fs = $provideFilesystemForNode();
6992
- return [4 /*yield*/, $provideExecutablesForNode()];
6993
- case 3:
6994
- executables = _b.sent();
6995
- _a = {
6996
- llm: llm,
6997
- fs: fs
6998
- };
6999
- return [4 /*yield*/, $provideScrapersForNode({ fs: fs, llm: llm, executables: executables })];
7000
- case 4:
7001
- tools = (_a.scrapers = _b.sent(),
7002
- _a);
7053
+ tools = _b.sent();
7003
7054
  pipelineExecutor = createPipelineExecutor(__assign({ pipeline: pipeline, tools: tools }, options));
7004
7055
  executionTask = pipelineExecutor(inputParameters);
7005
7056
  runningExecutionTasks.push(executionTask);
7057
+ return [4 /*yield*/, waitasecond.forTime(10)];
7058
+ case 3:
7059
+ _b.sent();
7060
+ // <- Note: Wait for a while to wait for quick responses or sudden but asynchronous errors
7061
+ // <- TODO: Put this into configuration
7006
7062
  response.send(executionTask);
7007
- return [2 /*return*/];
7063
+ return [3 /*break*/, 5];
7064
+ case 4:
7065
+ error_1 = _b.sent();
7066
+ if (!(error_1 instanceof Error)) {
7067
+ throw error_1;
7068
+ }
7069
+ response.status(400).send({ error: serializeError(error_1) });
7070
+ return [3 /*break*/, 5];
7071
+ case 5: return [2 /*return*/];
7008
7072
  }
7009
7073
  });
7010
7074
  }); });
@@ -7021,55 +7085,9 @@
7021
7085
  if (isVerbose) {
7022
7086
  console.info(colors__default["default"].gray("Client connected"), socket.id);
7023
7087
  }
7024
- var getExecutionToolsFromIdentification = function (identification) { return __awaiter(_this, void 0, void 0, function () {
7025
- var isAnonymous, llm, llmToolsConfiguration, appId, userId, customOptions, fs, executables, tools;
7026
- var _a;
7027
- return __generator(this, function (_b) {
7028
- switch (_b.label) {
7029
- case 0:
7030
- isAnonymous = identification.isAnonymous;
7031
- if (isAnonymous === true && !isAnonymousModeAllowed) {
7032
- throw new PipelineExecutionError("Anonymous mode is not allowed"); // <- TODO: [main] !!3 Test
7033
- }
7034
- if (isAnonymous === false && !isApplicationModeAllowed) {
7035
- throw new PipelineExecutionError("Application mode is not allowed"); // <- TODO: [main] !!3 Test
7036
- }
7037
- if (!(isAnonymous === true)) return [3 /*break*/, 1];
7038
- llmToolsConfiguration = identification.llmToolsConfiguration;
7039
- llm = createLlmToolsFromConfiguration(llmToolsConfiguration, { isVerbose: isVerbose });
7040
- return [3 /*break*/, 4];
7041
- case 1:
7042
- if (!(isAnonymous === false && createLlmExecutionTools !== null)) return [3 /*break*/, 3];
7043
- appId = identification.appId, userId = identification.userId, customOptions = identification.customOptions;
7044
- return [4 /*yield*/, createLlmExecutionTools({
7045
- appId: appId,
7046
- userId: userId,
7047
- customOptions: customOptions,
7048
- })];
7049
- case 2:
7050
- llm = _b.sent();
7051
- return [3 /*break*/, 4];
7052
- case 3: throw new PipelineExecutionError("You must provide either llmToolsConfiguration or non-anonymous mode must be propperly configured");
7053
- case 4:
7054
- fs = $provideFilesystemForNode();
7055
- return [4 /*yield*/, $provideExecutablesForNode()];
7056
- case 5:
7057
- executables = _b.sent();
7058
- _a = {
7059
- llm: llm,
7060
- fs: fs
7061
- };
7062
- return [4 /*yield*/, $provideScrapersForNode({ fs: fs, llm: llm, executables: executables })];
7063
- case 6:
7064
- tools = (_a.scrapers = _b.sent(),
7065
- _a);
7066
- return [2 /*return*/, tools];
7067
- }
7068
- });
7069
- }); };
7070
7088
  // -----------
7071
7089
  socket.on('prompt-request', function (request) { return __awaiter(_this, void 0, void 0, function () {
7072
- var identification, prompt, executionTools, llm, _a, promptResult, _b, error_1;
7090
+ var identification, prompt, tools, llm, _a, promptResult, _b, error_2;
7073
7091
  return __generator(this, function (_c) {
7074
7092
  switch (_c.label) {
7075
7093
  case 0:
@@ -7082,8 +7100,8 @@
7082
7100
  _c.trys.push([1, 13, 14, 15]);
7083
7101
  return [4 /*yield*/, getExecutionToolsFromIdentification(identification)];
7084
7102
  case 2:
7085
- executionTools = _c.sent();
7086
- llm = executionTools.llm;
7103
+ tools = _c.sent();
7104
+ llm = tools.llm;
7087
7105
  _a = identification.isAnonymous === false &&
7088
7106
  collection !== null;
7089
7107
  if (!_a) return [3 /*break*/, 4];
@@ -7138,11 +7156,11 @@
7138
7156
  socket.emit('prompt-response', { promptResult: promptResult } /* <- Note: [🤛] */);
7139
7157
  return [3 /*break*/, 15];
7140
7158
  case 13:
7141
- error_1 = _c.sent();
7142
- if (!(error_1 instanceof Error)) {
7143
- throw error_1;
7159
+ error_2 = _c.sent();
7160
+ if (!(error_2 instanceof Error)) {
7161
+ throw error_2;
7144
7162
  }
7145
- socket.emit('error', serializeError(error_1) /* <- Note: [🤛] */);
7163
+ socket.emit('error', serializeError(error_2) /* <- Note: [🤛] */);
7146
7164
  return [3 /*break*/, 15];
7147
7165
  case 14:
7148
7166
  socket.disconnect();
@@ -7154,7 +7172,7 @@
7154
7172
  // -----------
7155
7173
  // TODO: [👒] Listing models (and checking configuration) probbably should go through REST API not Socket.io
7156
7174
  socket.on('listModels-request', function (request) { return __awaiter(_this, void 0, void 0, function () {
7157
- var identification, executionTools, llm, models, error_2;
7175
+ var identification, tools, llm, models, error_3;
7158
7176
  return __generator(this, function (_a) {
7159
7177
  switch (_a.label) {
7160
7178
  case 0:
@@ -7167,19 +7185,19 @@
7167
7185
  _a.trys.push([1, 4, 5, 6]);
7168
7186
  return [4 /*yield*/, getExecutionToolsFromIdentification(identification)];
7169
7187
  case 2:
7170
- executionTools = _a.sent();
7171
- llm = executionTools.llm;
7188
+ tools = _a.sent();
7189
+ llm = tools.llm;
7172
7190
  return [4 /*yield*/, llm.listModels()];
7173
7191
  case 3:
7174
7192
  models = _a.sent();
7175
7193
  socket.emit('listModels-response', { models: models } /* <- Note: [🤛] */);
7176
7194
  return [3 /*break*/, 6];
7177
7195
  case 4:
7178
- error_2 = _a.sent();
7179
- if (!(error_2 instanceof Error)) {
7180
- throw error_2;
7196
+ error_3 = _a.sent();
7197
+ if (!(error_3 instanceof Error)) {
7198
+ throw error_3;
7181
7199
  }
7182
- socket.emit('error', serializeError(error_2));
7200
+ socket.emit('error', serializeError(error_3));
7183
7201
  return [3 /*break*/, 6];
7184
7202
  case 5:
7185
7203
  socket.disconnect();
@@ -7191,7 +7209,7 @@
7191
7209
  // -----------
7192
7210
  // TODO: [👒] Listing models (and checking configuration) probbably should go through REST API not Socket.io
7193
7211
  socket.on('preparePipeline-request', function (request) { return __awaiter(_this, void 0, void 0, function () {
7194
- var identification, pipeline, executionTools, preparedPipeline, error_3;
7212
+ var identification, pipeline, tools, preparedPipeline, error_4;
7195
7213
  return __generator(this, function (_a) {
7196
7214
  switch (_a.label) {
7197
7215
  case 0:
@@ -7204,18 +7222,18 @@
7204
7222
  _a.trys.push([1, 4, 5, 6]);
7205
7223
  return [4 /*yield*/, getExecutionToolsFromIdentification(identification)];
7206
7224
  case 2:
7207
- executionTools = _a.sent();
7208
- return [4 /*yield*/, preparePipeline(pipeline, executionTools, options)];
7225
+ tools = _a.sent();
7226
+ return [4 /*yield*/, preparePipeline(pipeline, tools, options)];
7209
7227
  case 3:
7210
7228
  preparedPipeline = _a.sent();
7211
7229
  socket.emit('preparePipeline-response', { preparedPipeline: preparedPipeline } /* <- Note: [🤛] */);
7212
7230
  return [3 /*break*/, 6];
7213
7231
  case 4:
7214
- error_3 = _a.sent();
7215
- if (!(error_3 instanceof Error)) {
7216
- throw error_3;
7232
+ error_4 = _a.sent();
7233
+ if (!(error_4 instanceof Error)) {
7234
+ throw error_4;
7217
7235
  }
7218
- socket.emit('error', serializeError(error_3));
7236
+ socket.emit('error', serializeError(error_4));
7219
7237
  return [3 /*break*/, 6];
7220
7238
  case 5:
7221
7239
  socket.disconnect();
@@ -7254,8 +7272,7 @@
7254
7272
  };
7255
7273
  }
7256
7274
  /**
7257
- * TODO: !!!!!!! CORS and security
7258
- * TODO: !!!!!!! Allow to pass tokem here
7275
+ * TODO: !! Add CORS and security - probbably via `helmet`
7259
7276
  * TODO: [👩🏾‍🤝‍🧑🏾] Allow to pass custom fetch function here - PromptbookFetch
7260
7277
  * TODO: Split this file into multiple functions - handler for each request
7261
7278
  * TODO: Maybe use `$exportJson`