@promptbook/remote-server 0.85.0-4 → 0.85.0-6

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.
@@ -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
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/remote-server",
3
- "version": "0.85.0-4",
3
+ "version": "0.85.0-6",
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-4"
50
+ "@promptbook/core": "0.85.0-6"
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-3';
31
+ var PROMPTBOOK_ENGINE_VERSION = '0.85.0-5';
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:
@@ -2011,6 +2011,24 @@
2011
2011
  var finalResultPromise = /* not await */ taskProcessCallback(function (newOngoingResult) {
2012
2012
  partialResultSubject.next(newOngoingResult);
2013
2013
  });
2014
+ finalResultPromise
2015
+ .catch(function (error) {
2016
+ // console.error('!!!!! Task failed:', error);
2017
+ partialResultSubject.error(error);
2018
+ })
2019
+ .then(function (value) {
2020
+ // console.error('!!!!! Task finished:', value);
2021
+ if (value) {
2022
+ try {
2023
+ assertsTaskSuccessful(value);
2024
+ partialResultSubject.next(value);
2025
+ }
2026
+ catch (error) {
2027
+ partialResultSubject.error(error);
2028
+ }
2029
+ }
2030
+ partialResultSubject.complete();
2031
+ });
2014
2032
  function asPromise(options) {
2015
2033
  return __awaiter(this, void 0, void 0, function () {
2016
2034
  var _a, isCrashedOnError, finalResult;
@@ -2021,7 +2039,9 @@
2021
2039
  return [4 /*yield*/, finalResultPromise];
2022
2040
  case 1:
2023
2041
  finalResult = _b.sent();
2042
+ console.error('!!!!! finalResult:', finalResult);
2024
2043
  if (isCrashedOnError) {
2044
+ console.error('!!!!! isCrashedOnError:', finalResult);
2025
2045
  assertsTaskSuccessful(finalResult);
2026
2046
  }
2027
2047
  return [2 /*return*/, finalResult];
@@ -2034,9 +2054,7 @@
2034
2054
  taskId: taskId,
2035
2055
  asPromise: asPromise,
2036
2056
  asObservable: function () {
2037
- return rxjs.concat(partialResultSubject.asObservable(), rxjs.from(asPromise({
2038
- isCrashedOnError: true,
2039
- })));
2057
+ return partialResultSubject.asObservable();
2040
2058
  },
2041
2059
  get currentValue() {
2042
2060
  return partialResultSubject.value;
@@ -3982,7 +4000,7 @@
3982
4000
  value = value.replace(/\.html$/, '');
3983
4001
  }
3984
4002
  else if (isValidFilePath(value)) {
3985
- value = node_path.basename(value);
4003
+ value = path.basename(value);
3986
4004
  // Note: Keeping extension in the name
3987
4005
  }
3988
4006
  value = value.split('/').join('-');
@@ -4088,9 +4106,9 @@
4088
4106
  }
4089
4107
  basename = url.split('/').pop() || titleToName(url);
4090
4108
  hash = sha256__default["default"](hexEncoder__default["default"].parse(url)).toString( /* hex */);
4091
- rootDirname_1 = node_path.join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
4092
- 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));
4093
- return [4 /*yield*/, tools.fs.mkdir(node_path.dirname(node_path.join(rootDirname_1, filepath)), { recursive: true })];
4109
+ rootDirname_1 = path.join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
4110
+ 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));
4111
+ return [4 /*yield*/, tools.fs.mkdir(path.dirname(path.join(rootDirname_1, filepath)), { recursive: true })];
4094
4112
  case 2:
4095
4113
  _h.sent();
4096
4114
  _g = (_f = Buffer).from;
@@ -4100,7 +4118,7 @@
4100
4118
  if (fileContent.length > DEFAULT_MAX_FILE_SIZE /* <- TODO: Allow to pass different value to remote server */) {
4101
4119
  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."));
4102
4120
  }
4103
- return [4 /*yield*/, tools.fs.writeFile(node_path.join(rootDirname_1, filepath), fileContent)];
4121
+ return [4 /*yield*/, tools.fs.writeFile(path.join(rootDirname_1, filepath), fileContent)];
4104
4122
  case 4:
4105
4123
  _h.sent();
4106
4124
  // TODO: [💵] Check the file security
@@ -4116,7 +4134,7 @@
4116
4134
  throw new EnvironmentMismatchError('Can not import file knowledge in non-file pipeline');
4117
4135
  // <- TODO: [🧠] What is the best error type here`
4118
4136
  }
4119
- filename_1 = node_path.join(rootDirname, knowledgeSourceContent).split('\\').join('/');
4137
+ filename_1 = path.join(rootDirname, knowledgeSourceContent).split('\\').join('/');
4120
4138
  fileExtension = getFileExtension(filename_1);
4121
4139
  mimeType = extensionToMimeType(fileExtension || '');
4122
4140
  return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
@@ -6883,7 +6901,7 @@
6883
6901
  next();
6884
6902
  });
6885
6903
  var runningExecutionTasks = [];
6886
- // TODO: !!!!!! Do here some garbage collection of finished tasks
6904
+ // TODO: [🧠] Do here some garbage collection of finished tasks
6887
6905
  app.get(['/', rootPath], function (request, response) { return __awaiter(_this, void 0, void 0, function () {
6888
6906
  var _a, _b;
6889
6907
  var _this = this;
@@ -6932,20 +6950,19 @@
6932
6950
  });
6933
6951
  }); });
6934
6952
  app.get("".concat(rootPath, "/books"), function (request, response) { return __awaiter(_this, void 0, void 0, function () {
6935
- var _a, _b, _c;
6936
- return __generator(this, function (_d) {
6937
- switch (_d.label) {
6953
+ var pipelines;
6954
+ return __generator(this, function (_a) {
6955
+ switch (_a.label) {
6938
6956
  case 0:
6939
- _b = (_a = response).send;
6940
- if (!(collection === null)) return [3 /*break*/, 1];
6941
- _c = [];
6942
- return [3 /*break*/, 3];
6943
- case 1: return [4 /*yield*/, collection.listPipelines()];
6944
- case 2:
6945
- _c = _d.sent();
6946
- _d.label = 3;
6947
- case 3:
6948
- _b.apply(_a, [_c]);
6957
+ if (collection === null) {
6958
+ response.status(500).send('No collection available');
6959
+ return [2 /*return*/];
6960
+ }
6961
+ return [4 /*yield*/, collection.listPipelines()];
6962
+ case 1:
6963
+ pipelines = _a.sent();
6964
+ // <- TODO: [🧠][👩🏾‍🤝‍🧑🏿] List `inputParameters` required for the execution
6965
+ response.send(pipelines);
6949
6966
  return [2 /*return*/];
6950
6967
  }
6951
6968
  });
@@ -6975,13 +6992,12 @@
6975
6992
  return __generator(this, function (_b) {
6976
6993
  switch (_b.label) {
6977
6994
  case 0:
6978
- _b.trys.push([0, 5, , 6]);
6995
+ _b.trys.push([0, 6, , 7]);
6979
6996
  inputParameters = request.body.inputParameters;
6980
6997
  pipelineUrl = request.body.pipelineUrl || request.body.book;
6981
6998
  return [4 /*yield*/, (collection === null || collection === void 0 ? void 0 : collection.getPipelineByUrl(pipelineUrl))];
6982
6999
  case 1:
6983
7000
  pipeline = _b.sent();
6984
- // <- TODO: !!!!!! NotFoundError
6985
7001
  if (pipeline === undefined) {
6986
7002
  response.status(404).send("Pipeline \"".concat(pipelineUrl, "\" not found"));
6987
7003
  return [2 /*return*/];
@@ -7008,20 +7024,21 @@
7008
7024
  pipelineExecutor = createPipelineExecutor(__assign({ pipeline: pipeline, tools: tools }, options));
7009
7025
  executionTask = pipelineExecutor(inputParameters);
7010
7026
  runningExecutionTasks.push(executionTask);
7011
- response.send(executionTask);
7012
- // TODO: !!!!!! Remove this:
7013
- executionTask.asObservable().subscribe(function (_) {
7014
- console.log('!!!', _);
7015
- });
7016
- return [3 /*break*/, 6];
7027
+ return [4 /*yield*/, waitasecond.forTime(10)];
7017
7028
  case 5:
7029
+ _b.sent();
7030
+ // <- Note: Wait for a while to wait for quick responses or sudden but asynchronous errors
7031
+ // <- TODO: Put this into configuration
7032
+ response.send(executionTask);
7033
+ return [3 /*break*/, 7];
7034
+ case 6:
7018
7035
  error_1 = _b.sent();
7019
7036
  if (!(error_1 instanceof Error)) {
7020
7037
  throw error_1;
7021
7038
  }
7022
7039
  response.status(400).send({ error: serializeError(error_1) });
7023
- return [3 /*break*/, 6];
7024
- case 6: return [2 /*return*/];
7040
+ return [3 /*break*/, 7];
7041
+ case 7: return [2 /*return*/];
7025
7042
  }
7026
7043
  });
7027
7044
  }); });