@promptbook/node 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/node",
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,12 +42,12 @@
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
  "main": "./umd/index.umd.js",
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-8"
50
+ "@promptbook/core": "0.85.0"
51
51
  },
52
52
  "dependencies": {
53
53
  "colors": "1.4.0",
package/umd/index.umd.js CHANGED
@@ -45,7 +45,7 @@
45
45
  * @generated
46
46
  * @see https://github.com/webgptorg/promptbook
47
47
  */
48
- var PROMPTBOOK_ENGINE_VERSION = '0.85.0-7';
48
+ var PROMPTBOOK_ENGINE_VERSION = '0.85.0-16';
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
@@ -1152,57 +1152,6 @@
1152
1152
  return true;
1153
1153
  }
1154
1154
 
1155
- /**
1156
- * Checks if an URL is reserved for private networks or localhost.
1157
- *
1158
- * Note: There are two simmilar functions:
1159
- * - `isUrlOnPrivateNetwork` which tests full URL
1160
- * - `isHostnameOnPrivateNetwork` *(this one)* which tests just hostname
1161
- *
1162
- * @public exported from `@promptbook/utils`
1163
- */
1164
- function isHostnameOnPrivateNetwork(hostname) {
1165
- if (hostname === 'example.com' ||
1166
- hostname === 'localhost' ||
1167
- hostname.endsWith('.localhost') ||
1168
- hostname.endsWith('.local') ||
1169
- hostname.endsWith('.test') ||
1170
- hostname === '127.0.0.1' ||
1171
- hostname === '::1') {
1172
- return true;
1173
- }
1174
- if (hostname.includes(':')) {
1175
- // IPv6
1176
- var ipParts = hostname.split(':');
1177
- return ipParts[0] === 'fc00' || ipParts[0] === 'fd00' || ipParts[0] === 'fe80';
1178
- }
1179
- else {
1180
- // IPv4
1181
- var ipParts = hostname.split('.').map(function (part) { return Number.parseInt(part, 10); });
1182
- return (ipParts[0] === 10 ||
1183
- (ipParts[0] === 172 && ipParts[1] >= 16 && ipParts[1] <= 31) ||
1184
- (ipParts[0] === 192 && ipParts[1] === 168));
1185
- }
1186
- }
1187
-
1188
- /**
1189
- * Checks if an IP address or hostname is reserved for private networks or localhost.
1190
- *
1191
- * Note: There are two simmilar functions:
1192
- * - `isUrlOnPrivateNetwork` *(this one)* which tests full URL
1193
- * - `isHostnameOnPrivateNetwork` which tests just hostname
1194
- *
1195
- * @param {string} ipAddress - The IP address to check.
1196
- * @returns {boolean} Returns true if the IP address is reserved for private networks or localhost, otherwise false.
1197
- * @public exported from `@promptbook/utils`
1198
- */
1199
- function isUrlOnPrivateNetwork(url) {
1200
- if (typeof url === 'string') {
1201
- url = new URL(url);
1202
- }
1203
- return isHostnameOnPrivateNetwork(url.hostname);
1204
- }
1205
-
1206
1155
  /**
1207
1156
  * Tests if given string is valid pipeline URL URL.
1208
1157
  *
@@ -1216,16 +1165,19 @@
1216
1165
  if (!isValidUrl(url)) {
1217
1166
  return false;
1218
1167
  }
1219
- if (!url.startsWith('https://')) {
1168
+ if (!url.startsWith('https://') && !url.startsWith('http://') /* <- Note: [👣] */) {
1220
1169
  return false;
1221
1170
  }
1222
1171
  if (url.includes('#')) {
1223
1172
  // TODO: [🐠]
1224
1173
  return false;
1225
1174
  }
1175
+ /*
1176
+ Note: [👣][🧠] Is it secure to allow pipeline URLs on private and unsecured networks?
1226
1177
  if (isUrlOnPrivateNetwork(url)) {
1227
1178
  return false;
1228
1179
  }
1180
+ */
1229
1181
  return true;
1230
1182
  }
1231
1183
  /**
@@ -2060,18 +2012,16 @@
2060
2012
  */
2061
2013
  function createTask(options) {
2062
2014
  var taskType = options.taskType, taskProcessCallback = options.taskProcessCallback;
2063
- var taskId = "".concat(taskType.toLowerCase().substring(0, 4), "-").concat($randomToken(8 /* <- TODO: !!! To global config + Use Base58 to avoid simmilar char conflicts */));
2015
+ var taskId = "".concat(taskType.toLowerCase().substring(0, 4), "-").concat($randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */));
2064
2016
  var partialResultSubject = new rxjs.BehaviorSubject({});
2065
2017
  var finalResultPromise = /* not await */ taskProcessCallback(function (newOngoingResult) {
2066
2018
  partialResultSubject.next(newOngoingResult);
2067
2019
  });
2068
2020
  finalResultPromise
2069
2021
  .catch(function (error) {
2070
- // console.error('!!!!! Task failed:', error);
2071
2022
  partialResultSubject.error(error);
2072
2023
  })
2073
2024
  .then(function (value) {
2074
- // console.error('!!!!! Task finished:', value);
2075
2025
  if (value) {
2076
2026
  try {
2077
2027
  assertsTaskSuccessful(value);
@@ -2093,9 +2043,7 @@
2093
2043
  return [4 /*yield*/, finalResultPromise];
2094
2044
  case 1:
2095
2045
  finalResult = _b.sent();
2096
- console.error('!!!!! finalResult:', finalResult);
2097
2046
  if (isCrashedOnError) {
2098
- console.error('!!!!! isCrashedOnError:', finalResult);
2099
2047
  assertsTaskSuccessful(finalResult);
2100
2048
  }
2101
2049
  return [2 /*return*/, finalResult];
@@ -11309,13 +11257,13 @@
11309
11257
  *
11310
11258
  * Note: Works only in Node.js environment because it reads the file system
11311
11259
  *
11312
- * @param path - path to the directory with pipelines
11260
+ * @param rootPath - path to the directory with pipelines
11313
11261
  * @param tools - Execution tools to be used for pipeline preparation if needed - If not provided, `$provideExecutionToolsForNode` will be used
11314
11262
  * @param options - Options for the collection creation
11315
11263
  * @returns PipelineCollection
11316
11264
  * @public exported from `@promptbook/node`
11317
11265
  */
11318
- function createCollectionFromDirectory(path$1, tools, options) {
11266
+ function createCollectionFromDirectory(rootPath, tools, options) {
11319
11267
  return __awaiter(this, void 0, void 0, function () {
11320
11268
  var madeLibraryFilePath, _a, _b, isRecursive, _c, isVerbose, _d, isLazyLoaded, _e, isCrashedOnError, rootUrl, collection;
11321
11269
  var _this = this;
@@ -11332,7 +11280,7 @@
11332
11280
  throw new EnvironmentMismatchError('Can not create collection without filesystem tools');
11333
11281
  // <- TODO: [🧠] What is the best error type here`
11334
11282
  }
11335
- madeLibraryFilePath = path.join(path$1, "".concat(DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME
11283
+ madeLibraryFilePath = path.join(rootPath, "".concat(DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME
11336
11284
  // <- TODO: [🦒] Allow to override (pass different value into the function)
11337
11285
  , ".json"));
11338
11286
  return [4 /*yield*/, isFileExisting(madeLibraryFilePath, tools.fs)];
@@ -11351,18 +11299,18 @@
11351
11299
  switch (_b.label) {
11352
11300
  case 0:
11353
11301
  if (isVerbose) {
11354
- console.info(colors__default["default"].cyan("Creating pipeline collection from path ".concat(path$1.split('\\').join('/'))));
11302
+ console.info(colors__default["default"].cyan("Creating pipeline collection from path ".concat(rootPath.split('\\').join('/'))));
11355
11303
  }
11356
- return [4 /*yield*/, listAllFiles(path$1, isRecursive, tools.fs)];
11304
+ return [4 /*yield*/, listAllFiles(rootPath, isRecursive, tools.fs)];
11357
11305
  case 1:
11358
11306
  fileNames = _b.sent();
11359
- // Note: First load all .book.json and then .book.md files
11360
- // .book.json can be prepared so it is faster to load
11307
+ // Note: First load all `.book.json` and then `.book` / `.book.md` files
11308
+ // `.book.json` can be prepared so it is faster to load
11361
11309
  fileNames.sort(function (a, b) {
11362
- if (a.endsWith('.json') && b.endsWith('.md')) {
11310
+ if (a.endsWith('.json') && (b.endsWith('.book') || b.endsWith('.book.md'))) {
11363
11311
  return -1;
11364
11312
  }
11365
- if (a.endsWith('.md') && b.endsWith('.json')) {
11313
+ if ((a.endsWith('.book') || a.endsWith('.book.md')) && b.endsWith('.json')) {
11366
11314
  return 1;
11367
11315
  }
11368
11316
  return 0;
@@ -11379,7 +11327,7 @@
11379
11327
  case 1:
11380
11328
  _f.trys.push([1, 8, , 9]);
11381
11329
  pipeline = null;
11382
- if (!fileName.endsWith('.book.md')) return [3 /*break*/, 4];
11330
+ if (!(fileName.endsWith('.book') || fileName.endsWith('.book.md'))) return [3 /*break*/, 4];
11383
11331
  _c = validatePipelineString;
11384
11332
  return [4 /*yield*/, promises.readFile(fileName, 'utf-8')];
11385
11333
  case 2:
@@ -11411,7 +11359,8 @@
11411
11359
  if (pipeline !== null) {
11412
11360
  if (rootUrl !== undefined) {
11413
11361
  if (pipeline.pipelineUrl === undefined) {
11414
- pipelineUrl = rootUrl + '/' + fileName.split('\\').join('/');
11362
+ pipelineUrl = rootUrl + '/' + path.relative(rootPath, fileName).split('\\').join('/');
11363
+ // console.log({ pipelineUrl, rootPath, rootUrl, fileName });
11415
11364
  if (isVerbose) {
11416
11365
  console.info(colors__default["default"].yellow("Implicitly set pipeline URL to ".concat(pipelineUrl, " from ").concat(fileName
11417
11366
  .split('\\')