@promptbook/node 0.85.0-0 → 0.85.0-2

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 };
@@ -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
  /**
@@ -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/node",
3
- "version": "0.85.0-0",
3
+ "version": "0.85.0-2",
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/node.index.d.ts",
49
49
  "peerDependencies": {
50
- "@promptbook/core": "0.85.0-0"
50
+ "@promptbook/core": "0.85.0-2"
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('fs/promises'), require('path'), require('spacetrim'), require('prettier'), require('prettier/parser-html'), require('rxjs'), require('crypto'), require('waitasecond'), require('papaparse'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('crypto-js'), require('mime-types'), require('child_process'), require('dotenv')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'colors', 'fs/promises', 'path', 'spacetrim', 'prettier', 'prettier/parser-html', 'rxjs', 'crypto', 'waitasecond', 'papaparse', 'crypto-js/enc-hex', 'crypto-js/sha256', 'crypto-js', 'mime-types', 'child_process', 'dotenv'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-node"] = {}, global.colors, global.promises, global.path, global.spaceTrim, global.prettier, global.parserHtml, global.rxjs, global.crypto, global.waitasecond, global.papaparse, global.hexEncoder, global.sha256, global.cryptoJs, global.mimeTypes, global.child_process, global.dotenv));
5
- })(this, (function (exports, colors, promises, path, spaceTrim, prettier, parserHtml, rxjs, crypto, waitasecond, papaparse, hexEncoder, sha256, cryptoJs, mimeTypes, child_process, dotenv) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('node:fs/promises'), require('node:path'), require('spacetrim'), require('prettier'), require('prettier/parser-html'), require('rxjs'), require('crypto'), require('waitasecond'), require('papaparse'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('crypto-js'), require('mime-types'), require('node:child_process'), require('dotenv')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'colors', 'node:fs/promises', 'node:path', 'spacetrim', 'prettier', 'prettier/parser-html', 'rxjs', 'crypto', 'waitasecond', 'papaparse', 'crypto-js/enc-hex', 'crypto-js/sha256', 'crypto-js', 'mime-types', 'node:child_process', 'dotenv'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-node"] = {}, global.colors, global.promises, global.node_path, global.spaceTrim, global.prettier, global.parserHtml, global.rxjs, global.crypto, global.waitasecond, global.papaparse, global.hexEncoder, global.sha256, global.cryptoJs, global.mimeTypes, global.node_child_process, global.dotenv));
5
+ })(this, (function (exports, colors, promises, node_path, spaceTrim, prettier, parserHtml, rxjs, crypto, waitasecond, papaparse, hexEncoder, sha256, cryptoJs, mimeTypes, node_child_process, dotenv) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -45,7 +45,7 @@
45
45
  * @generated
46
46
  * @see https://github.com/webgptorg/promptbook
47
47
  */
48
- var PROMPTBOOK_ENGINE_VERSION = '0.84.0';
48
+ var PROMPTBOOK_ENGINE_VERSION = '0.85.0-1';
49
49
  /**
50
50
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
51
51
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -2061,9 +2061,9 @@
2061
2061
  function createTask(options) {
2062
2062
  var taskType = options.taskType, taskProcessCallback = options.taskProcessCallback;
2063
2063
  var taskId = "".concat(taskType.toLowerCase(), "-").concat($randomToken(256 /* <- TODO: !!! To global config */));
2064
- var resultSubject = new rxjs.BehaviorSubject({});
2064
+ var partialResultSubject = new rxjs.BehaviorSubject({});
2065
2065
  var finalResultPromise = /* not await */ taskProcessCallback(function (newOngoingResult) {
2066
- resultSubject.next(newOngoingResult);
2066
+ partialResultSubject.next(newOngoingResult);
2067
2067
  });
2068
2068
  function asPromise(options) {
2069
2069
  return __awaiter(this, void 0, void 0, function () {
@@ -2088,7 +2088,7 @@
2088
2088
  taskId: taskId,
2089
2089
  asPromise: asPromise,
2090
2090
  asObservable: function () {
2091
- return rxjs.concat(resultSubject.asObservable(), rxjs.from(asPromise({
2091
+ return rxjs.concat(partialResultSubject.asObservable(), rxjs.from(asPromise({
2092
2092
  isCrashedOnError: true,
2093
2093
  })));
2094
2094
  },
@@ -5596,7 +5596,7 @@
5596
5596
  value = value.replace(/\.html$/, '');
5597
5597
  }
5598
5598
  else if (isValidFilePath(value)) {
5599
- value = path.basename(value);
5599
+ value = node_path.basename(value);
5600
5600
  // Note: Keeping extension in the name
5601
5601
  }
5602
5602
  value = value.split('/').join('-');
@@ -5702,9 +5702,9 @@
5702
5702
  }
5703
5703
  basename = url.split('/').pop() || titleToName(url);
5704
5704
  hash = sha256__default["default"](hexEncoder__default["default"].parse(url)).toString( /* hex */);
5705
- rootDirname_1 = path.join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
5706
- 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));
5707
- return [4 /*yield*/, tools.fs.mkdir(path.dirname(path.join(rootDirname_1, filepath)), { recursive: true })];
5705
+ rootDirname_1 = node_path.join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
5706
+ 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));
5707
+ return [4 /*yield*/, tools.fs.mkdir(node_path.dirname(node_path.join(rootDirname_1, filepath)), { recursive: true })];
5708
5708
  case 2:
5709
5709
  _h.sent();
5710
5710
  _g = (_f = Buffer).from;
@@ -5714,7 +5714,7 @@
5714
5714
  if (fileContent.length > DEFAULT_MAX_FILE_SIZE /* <- TODO: Allow to pass different value to remote server */) {
5715
5715
  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."));
5716
5716
  }
5717
- return [4 /*yield*/, tools.fs.writeFile(path.join(rootDirname_1, filepath), fileContent)];
5717
+ return [4 /*yield*/, tools.fs.writeFile(node_path.join(rootDirname_1, filepath), fileContent)];
5718
5718
  case 4:
5719
5719
  _h.sent();
5720
5720
  // TODO: [💵] Check the file security
@@ -5730,7 +5730,7 @@
5730
5730
  throw new EnvironmentMismatchError('Can not import file knowledge in non-file pipeline');
5731
5731
  // <- TODO: [🧠] What is the best error type here`
5732
5732
  }
5733
- filename_1 = path.join(rootDirname, knowledgeSourceContent).split('\\').join('/');
5733
+ filename_1 = node_path.join(rootDirname, knowledgeSourceContent).split('\\').join('/');
5734
5734
  fileExtension = getFileExtension(filename_1);
5735
5735
  mimeType = extensionToMimeType(fileExtension || '');
5736
5736
  return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
@@ -9726,7 +9726,7 @@
9726
9726
  console.info(colors__default["default"].yellow(cwd) + ' ' + colors__default["default"].green(command) + ' ' + colors__default["default"].blue(args.join(' ')));
9727
9727
  }
9728
9728
  try {
9729
- var commandProcess = child_process.spawn(command, args, { cwd: cwd, shell: true });
9729
+ var commandProcess = node_child_process.spawn(command, args, { cwd: cwd, shell: true });
9730
9730
  if (isVerbose) {
9731
9731
  commandProcess.on('message', function (message) {
9732
9732
  console.info({ message: message });
@@ -9936,7 +9936,7 @@
9936
9936
  function locateAppOnWindows(_a) {
9937
9937
  var appName = _a.appName, windowsSuffix = _a.windowsSuffix;
9938
9938
  return __awaiter(this, void 0, void 0, function () {
9939
- var prefixes, prefixes_1, prefixes_1_1, prefix, path$1, e_1_1, error_1;
9939
+ var prefixes, prefixes_1, prefixes_1_1, prefix, path, e_1_1, error_1;
9940
9940
  var e_1, _b;
9941
9941
  return __generator(this, function (_c) {
9942
9942
  switch (_c.label) {
@@ -9944,7 +9944,7 @@
9944
9944
  _c.trys.push([0, 9, , 10]);
9945
9945
  prefixes = [
9946
9946
  process.env.LOCALAPPDATA,
9947
- path.join(process.env.LOCALAPPDATA || '', 'Programs'),
9947
+ node_path.join(process.env.LOCALAPPDATA || '', 'Programs'),
9948
9948
  process.env.PROGRAMFILES,
9949
9949
  process.env['PROGRAMFILES(X86)'],
9950
9950
  ];
@@ -9956,11 +9956,11 @@
9956
9956
  case 2:
9957
9957
  if (!!prefixes_1_1.done) return [3 /*break*/, 5];
9958
9958
  prefix = prefixes_1_1.value;
9959
- path$1 = prefix + windowsSuffix;
9960
- return [4 /*yield*/, isExecutable(path$1, $provideFilesystemForNode())];
9959
+ path = prefix + windowsSuffix;
9960
+ return [4 /*yield*/, isExecutable(path, $provideFilesystemForNode())];
9961
9961
  case 3:
9962
9962
  if (_c.sent()) {
9963
- return [2 /*return*/, path$1];
9963
+ return [2 /*return*/, path];
9964
9964
  }
9965
9965
  _c.label = 4;
9966
9966
  case 4:
@@ -10356,7 +10356,7 @@
10356
10356
  case 3:
10357
10357
  if (!!envFilePatterns_1_1.done) return [3 /*break*/, 6];
10358
10358
  pattern = envFilePatterns_1_1.value;
10359
- envFilename = path.join(rootDirname, pattern);
10359
+ envFilename = node_path.join(rootDirname, pattern);
10360
10360
  return [4 /*yield*/, isFileExisting(envFilename, $provideFilesystemForNode())];
10361
10361
  case 4:
10362
10362
  if (_b.sent()) {
@@ -10384,7 +10384,7 @@
10384
10384
  return [3 /*break*/, 11];
10385
10385
  }
10386
10386
  // Note: If the directory does not exist, try the parent directory
10387
- rootDirname = path.join(rootDirname, '..');
10387
+ rootDirname = node_path.join(rootDirname, '..');
10388
10388
  _b.label = 10;
10389
10389
  case 10:
10390
10390
  i++;
@@ -11131,19 +11131,19 @@
11131
11131
  * @returns List of all files in the directory
11132
11132
  * @private internal function of `createCollectionFromDirectory`
11133
11133
  */
11134
- function listAllFiles(path$1, isRecursive, fs) {
11134
+ function listAllFiles(path, isRecursive, fs) {
11135
11135
  return __awaiter(this, void 0, void 0, function () {
11136
11136
  var dirents, fileNames, _a, _b, dirent, subPath, _c, _d, _e, _f, e_1_1;
11137
11137
  var e_1, _g;
11138
11138
  return __generator(this, function (_h) {
11139
11139
  switch (_h.label) {
11140
- case 0: return [4 /*yield*/, isDirectoryExisting(path$1, fs)];
11140
+ case 0: return [4 /*yield*/, isDirectoryExisting(path, fs)];
11141
11141
  case 1:
11142
11142
  if (!(_h.sent())) {
11143
- throw new Error("Directory \"".concat(path$1, "\" does not exist or is not readable"));
11143
+ throw new Error("Directory \"".concat(path, "\" does not exist or is not readable"));
11144
11144
  // <- TODO: Use some custom error class
11145
11145
  }
11146
- return [4 /*yield*/, fs.readdir(path$1, {
11146
+ return [4 /*yield*/, fs.readdir(path, {
11147
11147
  withFileTypes: true /* Note: This is not working: recursive: isRecursive */,
11148
11148
  })];
11149
11149
  case 2:
@@ -11152,7 +11152,7 @@
11152
11152
  .filter(function (dirent) { return dirent.isFile(); })
11153
11153
  .map(function (_a) {
11154
11154
  var name = _a.name;
11155
- return path.join(path$1, name).split('\\').join('/');
11155
+ return node_path.join(path, name).split('\\').join('/');
11156
11156
  });
11157
11157
  if (!isRecursive) return [3 /*break*/, 10];
11158
11158
  _h.label = 3;
@@ -11163,7 +11163,7 @@
11163
11163
  case 4:
11164
11164
  if (!!_b.done) return [3 /*break*/, 7];
11165
11165
  dirent = _b.value;
11166
- subPath = path.join(path$1, dirent.name);
11166
+ subPath = node_path.join(path, dirent.name);
11167
11167
  _d = (_c = fileNames.push).apply;
11168
11168
  _e = [fileNames];
11169
11169
  _f = [[]];
@@ -11294,7 +11294,7 @@
11294
11294
  * @returns PipelineCollection
11295
11295
  * @public exported from `@promptbook/node`
11296
11296
  */
11297
- function createCollectionFromDirectory(path$1, tools, options) {
11297
+ function createCollectionFromDirectory(path, tools, options) {
11298
11298
  return __awaiter(this, void 0, void 0, function () {
11299
11299
  var madeLibraryFilePath, _a, _b, isRecursive, _c, isVerbose, _d, isLazyLoaded, _e, isCrashedOnError, rootUrl, collection;
11300
11300
  var _this = this;
@@ -11311,7 +11311,7 @@
11311
11311
  throw new EnvironmentMismatchError('Can not create collection without filesystem tools');
11312
11312
  // <- TODO: [🧠] What is the best error type here`
11313
11313
  }
11314
- madeLibraryFilePath = path.join(path$1, "".concat(DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME
11314
+ madeLibraryFilePath = node_path.join(path, "".concat(DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME
11315
11315
  // <- TODO: [🦒] Allow to override (pass different value into the function)
11316
11316
  , ".json"));
11317
11317
  return [4 /*yield*/, isFileExisting(madeLibraryFilePath, tools.fs)];
@@ -11330,9 +11330,9 @@
11330
11330
  switch (_b.label) {
11331
11331
  case 0:
11332
11332
  if (isVerbose) {
11333
- console.info(colors__default["default"].cyan("Creating pipeline collection from path ".concat(path$1.split('\\').join('/'))));
11333
+ console.info(colors__default["default"].cyan("Creating pipeline collection from path ".concat(path.split('\\').join('/'))));
11334
11334
  }
11335
- return [4 /*yield*/, listAllFiles(path$1, isRecursive, tools.fs)];
11335
+ return [4 /*yield*/, listAllFiles(path, isRecursive, tools.fs)];
11336
11336
  case 1:
11337
11337
  fileNames = _b.sent();
11338
11338
  // Note: First load all .book.json and then .book.md files
@@ -11353,7 +11353,7 @@
11353
11353
  switch (_f.label) {
11354
11354
  case 0:
11355
11355
  sourceFile = './' + fileName.split('\\').join('/');
11356
- rootDirname = path.dirname(sourceFile).split('\\').join('/');
11356
+ rootDirname = node_path.dirname(sourceFile).split('\\').join('/');
11357
11357
  _f.label = 1;
11358
11358
  case 1:
11359
11359
  _f.trys.push([1, 8, , 9]);
@@ -11547,7 +11547,7 @@
11547
11547
  var name = titleToName(key);
11548
11548
  var hash = sha256__default["default"](hexEncoder__default["default"].parse(name)).toString( /* hex */);
11549
11549
  // <- TODO: [🥬] Encapsulate sha256 to some private utility function
11550
- return path.join.apply(void 0, __spreadArray(__spreadArray([this.options.rootFolderPath], __read(nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */)), false), ["".concat(name.substring(0, MAX_FILENAME_LENGTH), ".json")], false));
11550
+ return node_path.join.apply(void 0, __spreadArray(__spreadArray([this.options.rootFolderPath], __read(nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */)), false), ["".concat(name.substring(0, MAX_FILENAME_LENGTH), ".json")], false));
11551
11551
  };
11552
11552
  /**
11553
11553
  * @@@ Returns the current value associated with the given key, or null if the given key does not exist in the list associated with the object.
@@ -11588,7 +11588,7 @@
11588
11588
  throw new UnexpectedError("The \"".concat(key, "\" you want to store in JSON file is not serializable as JSON"));
11589
11589
  }
11590
11590
  fileContent = stringifyPipelineJson(value);
11591
- return [4 /*yield*/, promises.mkdir(path.dirname(filename), { recursive: true })];
11591
+ return [4 /*yield*/, promises.mkdir(node_path.dirname(filename), { recursive: true })];
11592
11592
  case 1:
11593
11593
  _a.sent(); // <- [0]
11594
11594
  return [4 /*yield*/, promises.writeFile(filename, fileContent, 'utf-8')];