@promptbook/node 0.85.0-9 → 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.
@@ -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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/node",
3
- "version": "0.85.0-9",
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-9"
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-8';
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
  /**
@@ -11305,13 +11257,13 @@
11305
11257
  *
11306
11258
  * Note: Works only in Node.js environment because it reads the file system
11307
11259
  *
11308
- * @param path - path to the directory with pipelines
11260
+ * @param rootPath - path to the directory with pipelines
11309
11261
  * @param tools - Execution tools to be used for pipeline preparation if needed - If not provided, `$provideExecutionToolsForNode` will be used
11310
11262
  * @param options - Options for the collection creation
11311
11263
  * @returns PipelineCollection
11312
11264
  * @public exported from `@promptbook/node`
11313
11265
  */
11314
- function createCollectionFromDirectory(path$1, tools, options) {
11266
+ function createCollectionFromDirectory(rootPath, tools, options) {
11315
11267
  return __awaiter(this, void 0, void 0, function () {
11316
11268
  var madeLibraryFilePath, _a, _b, isRecursive, _c, isVerbose, _d, isLazyLoaded, _e, isCrashedOnError, rootUrl, collection;
11317
11269
  var _this = this;
@@ -11328,7 +11280,7 @@
11328
11280
  throw new EnvironmentMismatchError('Can not create collection without filesystem tools');
11329
11281
  // <- TODO: [🧠] What is the best error type here`
11330
11282
  }
11331
- madeLibraryFilePath = path.join(path$1, "".concat(DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME
11283
+ madeLibraryFilePath = path.join(rootPath, "".concat(DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME
11332
11284
  // <- TODO: [🦒] Allow to override (pass different value into the function)
11333
11285
  , ".json"));
11334
11286
  return [4 /*yield*/, isFileExisting(madeLibraryFilePath, tools.fs)];
@@ -11347,18 +11299,18 @@
11347
11299
  switch (_b.label) {
11348
11300
  case 0:
11349
11301
  if (isVerbose) {
11350
- 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('/'))));
11351
11303
  }
11352
- return [4 /*yield*/, listAllFiles(path$1, isRecursive, tools.fs)];
11304
+ return [4 /*yield*/, listAllFiles(rootPath, isRecursive, tools.fs)];
11353
11305
  case 1:
11354
11306
  fileNames = _b.sent();
11355
- // Note: First load all .book.json and then .book.md files
11356
- // .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
11357
11309
  fileNames.sort(function (a, b) {
11358
- if (a.endsWith('.json') && b.endsWith('.md')) {
11310
+ if (a.endsWith('.json') && (b.endsWith('.book') || b.endsWith('.book.md'))) {
11359
11311
  return -1;
11360
11312
  }
11361
- if (a.endsWith('.md') && b.endsWith('.json')) {
11313
+ if ((a.endsWith('.book') || a.endsWith('.book.md')) && b.endsWith('.json')) {
11362
11314
  return 1;
11363
11315
  }
11364
11316
  return 0;
@@ -11375,7 +11327,7 @@
11375
11327
  case 1:
11376
11328
  _f.trys.push([1, 8, , 9]);
11377
11329
  pipeline = null;
11378
- if (!fileName.endsWith('.book.md')) return [3 /*break*/, 4];
11330
+ if (!(fileName.endsWith('.book') || fileName.endsWith('.book.md'))) return [3 /*break*/, 4];
11379
11331
  _c = validatePipelineString;
11380
11332
  return [4 /*yield*/, promises.readFile(fileName, 'utf-8')];
11381
11333
  case 2:
@@ -11407,7 +11359,8 @@
11407
11359
  if (pipeline !== null) {
11408
11360
  if (rootUrl !== undefined) {
11409
11361
  if (pipeline.pipelineUrl === undefined) {
11410
- pipelineUrl = rootUrl + '/' + fileName.split('\\').join('/');
11362
+ pipelineUrl = rootUrl + '/' + path.relative(rootPath, fileName).split('\\').join('/');
11363
+ // console.log({ pipelineUrl, rootPath, rootUrl, fileName });
11411
11364
  if (isVerbose) {
11412
11365
  console.info(colors__default["default"].yellow("Implicitly set pipeline URL to ".concat(pipelineUrl, " from ").concat(fileName
11413
11366
  .split('\\')