@promptbook/legacy-documents 0.85.0-0 → 0.85.0-1

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 'fs/promises';
2
+ import type fs from 'node:fs/promises';
3
3
  /**
4
4
  * Container for all the tools needed to manipulate with filesystem
5
5
  */
@@ -11,6 +11,8 @@ 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
16
  * TODO: [👩🏾‍🤝‍🧑🏾] Allow to pass custom fetch function here - PromptbookFetch
15
17
  * TODO: Split this file into multiple functions - handler for each request
16
18
  * TODO: Maybe use `$exportJson`
@@ -25,12 +25,14 @@ export type RemoteServerOptions<TCustomOptions> = CommonToolsOptions & {
25
25
  */
26
26
  readonly port: number;
27
27
  /**
28
- * Path for the Socket.io server to listen
28
+ * Root path of the server
29
29
  *
30
- * @default '/socket.io'
31
- * @example '/promptbook/socket.io'
30
+ * Note: This is useful when you reverse proxy the server without changing the path
31
+ *
32
+ * @default '/'
33
+ * @example '/api/promptbook/'
32
34
  */
33
- readonly path: string_uri;
35
+ readonly rootPath: string_uri;
34
36
  } & (AnonymousRemoteServerOptions | ApplicationRemoteServerOptions<TCustomOptions> | (AnonymousRemoteServerOptions & ApplicationRemoteServerOptions<TCustomOptions>));
35
37
  export type AnonymousRemoteServerOptions = {
36
38
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/legacy-documents",
3
- "version": "0.85.0-0",
3
+ "version": "0.85.0-1",
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/legacy-documents.index.d.ts",
49
49
  "peerDependencies": {
50
- "@promptbook/core": "0.85.0-0"
50
+ "@promptbook/core": "0.85.0-1"
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('fs/promises'), require('path'), require('spacetrim'), require('child_process'), require('colors'), require('waitasecond'), require('crypto-js'), require('crypto-js/enc-hex'), require('prettier'), require('prettier/parser-html'), require('rxjs'), require('crypto'), require('crypto-js/sha256'), require('mime-types'), require('papaparse')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'fs/promises', 'path', 'spacetrim', 'child_process', 'colors', 'waitasecond', 'crypto-js', 'crypto-js/enc-hex', 'prettier', 'prettier/parser-html', 'rxjs', 'crypto', 'crypto-js/sha256', 'mime-types', 'papaparse'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-legacy-documents"] = {}, global.promises, global.path, global.spaceTrim, global.child_process, global.colors, global.waitasecond, global.cryptoJs, global.hexEncoder, global.prettier, global.parserHtml, global.rxjs, global.crypto, global.sha256, global.mimeTypes, global.papaparse));
5
- })(this, (function (exports, promises, path, spaceTrim, child_process, colors, waitasecond, cryptoJs, hexEncoder, prettier, parserHtml, rxjs, crypto, sha256, mimeTypes, papaparse) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('node:fs/promises'), require('node:path'), require('spacetrim'), require('colors'), require('node:child_process'), require('waitasecond'), require('crypto-js'), require('crypto-js/enc-hex'), require('prettier'), require('prettier/parser-html'), require('rxjs'), require('crypto'), require('crypto-js/sha256'), require('mime-types'), require('papaparse')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'node:fs/promises', 'node:path', 'spacetrim', 'colors', 'node:child_process', 'waitasecond', 'crypto-js', 'crypto-js/enc-hex', 'prettier', 'prettier/parser-html', 'rxjs', 'crypto', 'crypto-js/sha256', 'mime-types', 'papaparse'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-legacy-documents"] = {}, global.promises, global.node_path, global.spaceTrim, global.colors, global.node_child_process, global.waitasecond, global.cryptoJs, global.hexEncoder, global.prettier, global.parserHtml, global.rxjs, global.crypto, global.sha256, global.mimeTypes, global.papaparse));
5
+ })(this, (function (exports, promises, node_path, spaceTrim, colors, node_child_process, waitasecond, cryptoJs, hexEncoder, prettier, parserHtml, rxjs, crypto, sha256, mimeTypes, papaparse) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -26,7 +26,7 @@
26
26
  * @generated
27
27
  * @see https://github.com/webgptorg/promptbook
28
28
  */
29
- var PROMPTBOOK_ENGINE_VERSION = '0.84.0';
29
+ var PROMPTBOOK_ENGINE_VERSION = '0.85.0-0';
30
30
  /**
31
31
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
32
32
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -508,7 +508,7 @@
508
508
  console.info(colors__default["default"].yellow(cwd) + ' ' + colors__default["default"].green(command) + ' ' + colors__default["default"].blue(args.join(' ')));
509
509
  }
510
510
  try {
511
- var commandProcess = child_process.spawn(command, args, { cwd: cwd, shell: true });
511
+ var commandProcess = node_child_process.spawn(command, args, { cwd: cwd, shell: true });
512
512
  if (isVerbose) {
513
513
  commandProcess.on('message', function (message) {
514
514
  console.info({ message: message });
@@ -1058,7 +1058,7 @@
1058
1058
  value = value.replace(/\.html$/, '');
1059
1059
  }
1060
1060
  else if (isValidFilePath(value)) {
1061
- value = path.basename(value);
1061
+ value = node_path.basename(value);
1062
1062
  // Note: Keeping extension in the name
1063
1063
  }
1064
1064
  value = value.split('/').join('-');
@@ -1091,12 +1091,12 @@
1091
1091
  semanticName = normalizeToKebabCase(titleToName((sourceFilename || url || '').split('intermediate').join(''))).substring(0, 20);
1092
1092
  pieces = ['intermediate', semanticName, hash].filter(function (piece) { return piece !== ''; });
1093
1093
  name = pieces.join('-').split('--').join('-');
1094
- cacheFilename = path.join.apply(void 0, __spreadArray(__spreadArray([process.cwd(),
1094
+ cacheFilename = node_path.join.apply(void 0, __spreadArray(__spreadArray([process.cwd(),
1095
1095
  cacheDirname], __read(nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */)), false), [name], false)).split('\\')
1096
1096
  .join('/') +
1097
1097
  '.' +
1098
1098
  extension;
1099
- return [4 /*yield*/, promises.mkdir(path.dirname(cacheFilename), { recursive: true })];
1099
+ return [4 /*yield*/, promises.mkdir(node_path.dirname(cacheFilename), { recursive: true })];
1100
1100
  case 1:
1101
1101
  _a.sent();
1102
1102
  isDestroyed = true;
@@ -2687,9 +2687,9 @@
2687
2687
  function createTask(options) {
2688
2688
  var taskType = options.taskType, taskProcessCallback = options.taskProcessCallback;
2689
2689
  var taskId = "".concat(taskType.toLowerCase(), "-").concat($randomToken(256 /* <- TODO: !!! To global config */));
2690
- var resultSubject = new rxjs.BehaviorSubject({});
2690
+ var partialResultSubject = new rxjs.BehaviorSubject({});
2691
2691
  var finalResultPromise = /* not await */ taskProcessCallback(function (newOngoingResult) {
2692
- resultSubject.next(newOngoingResult);
2692
+ partialResultSubject.next(newOngoingResult);
2693
2693
  });
2694
2694
  function asPromise(options) {
2695
2695
  return __awaiter(this, void 0, void 0, function () {
@@ -2714,7 +2714,7 @@
2714
2714
  taskId: taskId,
2715
2715
  asPromise: asPromise,
2716
2716
  asObservable: function () {
2717
- return rxjs.concat(resultSubject.asObservable(), rxjs.from(asPromise({
2717
+ return rxjs.concat(partialResultSubject.asObservable(), rxjs.from(asPromise({
2718
2718
  isCrashedOnError: true,
2719
2719
  })));
2720
2720
  },
@@ -3834,9 +3834,9 @@
3834
3834
  }
3835
3835
  basename = url.split('/').pop() || titleToName(url);
3836
3836
  hash = sha256__default["default"](hexEncoder__default["default"].parse(url)).toString( /* hex */);
3837
- rootDirname_1 = path.join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
3838
- 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));
3839
- return [4 /*yield*/, tools.fs.mkdir(path.dirname(path.join(rootDirname_1, filepath)), { recursive: true })];
3837
+ rootDirname_1 = node_path.join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
3838
+ 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));
3839
+ return [4 /*yield*/, tools.fs.mkdir(node_path.dirname(node_path.join(rootDirname_1, filepath)), { recursive: true })];
3840
3840
  case 2:
3841
3841
  _h.sent();
3842
3842
  _g = (_f = Buffer).from;
@@ -3846,7 +3846,7 @@
3846
3846
  if (fileContent.length > DEFAULT_MAX_FILE_SIZE /* <- TODO: Allow to pass different value to remote server */) {
3847
3847
  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."));
3848
3848
  }
3849
- return [4 /*yield*/, tools.fs.writeFile(path.join(rootDirname_1, filepath), fileContent)];
3849
+ return [4 /*yield*/, tools.fs.writeFile(node_path.join(rootDirname_1, filepath), fileContent)];
3850
3850
  case 4:
3851
3851
  _h.sent();
3852
3852
  // TODO: [💵] Check the file security
@@ -3862,7 +3862,7 @@
3862
3862
  throw new EnvironmentMismatchError('Can not import file knowledge in non-file pipeline');
3863
3863
  // <- TODO: [🧠] What is the best error type here`
3864
3864
  }
3865
- filename_1 = path.join(rootDirname, knowledgeSourceContent).split('\\').join('/');
3865
+ filename_1 = node_path.join(rootDirname, knowledgeSourceContent).split('\\').join('/');
3866
3866
  fileExtension = getFileExtension(filename_1);
3867
3867
  mimeType = extensionToMimeType(fileExtension || '');
3868
3868
  return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
@@ -6788,7 +6788,7 @@
6788
6788
  return [4 /*yield*/, isFileExisting(cacheFilehandler.filename, this.tools.fs)];
6789
6789
  case 2:
6790
6790
  if (!!(_g.sent())) return [3 /*break*/, 8];
6791
- documentSourceOutdirPathForLibreOffice_1 = path.join(path.dirname(cacheFilehandler.filename), 'libreoffice')
6791
+ documentSourceOutdirPathForLibreOffice_1 = node_path.join(node_path.dirname(cacheFilehandler.filename), 'libreoffice')
6792
6792
  .split('\\')
6793
6793
  .join('/');
6794
6794
  command_1 = "\"".concat(this.tools.executables.libreOfficePath, "\" --headless --convert-to docx \"").concat(source.filename, "\" --outdir \"").concat(documentSourceOutdirPathForLibreOffice_1, "\"");
@@ -6802,7 +6802,7 @@
6802
6802
  throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n Expected exactly 1 file in the LibreOffice output directory, got ".concat(files_1.length, "\n\n The temporary folder:\n ").concat(block(documentSourceOutdirPathForLibreOffice_1), "\n\n Command:\n > ").concat(block(command_1), "\n "); }));
6803
6803
  }
6804
6804
  file = files_1[0];
6805
- return [4 /*yield*/, promises.rename(path.join(documentSourceOutdirPathForLibreOffice_1, file), cacheFilehandler.filename)];
6805
+ return [4 /*yield*/, promises.rename(node_path.join(documentSourceOutdirPathForLibreOffice_1, file), cacheFilehandler.filename)];
6806
6806
  case 5:
6807
6807
  _g.sent();
6808
6808
  return [4 /*yield*/, promises.rmdir(documentSourceOutdirPathForLibreOffice_1)];