@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.
package/README.md CHANGED
@@ -24,10 +24,6 @@
24
24
 
25
25
 
26
26
 
27
- <blockquote style="color: #ff8811">
28
- <b>⚠ Warning:</b> This is a pre-release version of the library. It is not yet ready for production use. Please look at <a href="https://www.npmjs.com/package/@promptbook/core?activeTab=versions">latest stable release</a>.
29
- </blockquote>
30
-
31
27
  ## 📦 Package `@promptbook/node`
32
28
 
33
29
  - Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
package/esm/index.es.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import colors from 'colors';
2
2
  import { stat, access, constants, readFile, writeFile, readdir, mkdir, unlink } from 'fs/promises';
3
- import { basename, join, dirname } from 'path';
3
+ import { basename, join, dirname, relative } from 'path';
4
4
  import spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
5
5
  import { format } from 'prettier';
6
6
  import parserHtml from 'prettier/parser-html';
@@ -29,7 +29,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
29
29
  * @generated
30
30
  * @see https://github.com/webgptorg/promptbook
31
31
  */
32
- var PROMPTBOOK_ENGINE_VERSION = '0.85.0-8';
32
+ var PROMPTBOOK_ENGINE_VERSION = '0.85.0-16';
33
33
  /**
34
34
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
35
35
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -1136,57 +1136,6 @@ function isValidPromptbookVersion(version) {
1136
1136
  return true;
1137
1137
  }
1138
1138
 
1139
- /**
1140
- * Checks if an URL is reserved for private networks or localhost.
1141
- *
1142
- * Note: There are two simmilar functions:
1143
- * - `isUrlOnPrivateNetwork` which tests full URL
1144
- * - `isHostnameOnPrivateNetwork` *(this one)* which tests just hostname
1145
- *
1146
- * @public exported from `@promptbook/utils`
1147
- */
1148
- function isHostnameOnPrivateNetwork(hostname) {
1149
- if (hostname === 'example.com' ||
1150
- hostname === 'localhost' ||
1151
- hostname.endsWith('.localhost') ||
1152
- hostname.endsWith('.local') ||
1153
- hostname.endsWith('.test') ||
1154
- hostname === '127.0.0.1' ||
1155
- hostname === '::1') {
1156
- return true;
1157
- }
1158
- if (hostname.includes(':')) {
1159
- // IPv6
1160
- var ipParts = hostname.split(':');
1161
- return ipParts[0] === 'fc00' || ipParts[0] === 'fd00' || ipParts[0] === 'fe80';
1162
- }
1163
- else {
1164
- // IPv4
1165
- var ipParts = hostname.split('.').map(function (part) { return Number.parseInt(part, 10); });
1166
- return (ipParts[0] === 10 ||
1167
- (ipParts[0] === 172 && ipParts[1] >= 16 && ipParts[1] <= 31) ||
1168
- (ipParts[0] === 192 && ipParts[1] === 168));
1169
- }
1170
- }
1171
-
1172
- /**
1173
- * Checks if an IP address or hostname is reserved for private networks or localhost.
1174
- *
1175
- * Note: There are two simmilar functions:
1176
- * - `isUrlOnPrivateNetwork` *(this one)* which tests full URL
1177
- * - `isHostnameOnPrivateNetwork` which tests just hostname
1178
- *
1179
- * @param {string} ipAddress - The IP address to check.
1180
- * @returns {boolean} Returns true if the IP address is reserved for private networks or localhost, otherwise false.
1181
- * @public exported from `@promptbook/utils`
1182
- */
1183
- function isUrlOnPrivateNetwork(url) {
1184
- if (typeof url === 'string') {
1185
- url = new URL(url);
1186
- }
1187
- return isHostnameOnPrivateNetwork(url.hostname);
1188
- }
1189
-
1190
1139
  /**
1191
1140
  * Tests if given string is valid pipeline URL URL.
1192
1141
  *
@@ -1200,16 +1149,19 @@ function isValidPipelineUrl(url) {
1200
1149
  if (!isValidUrl(url)) {
1201
1150
  return false;
1202
1151
  }
1203
- if (!url.startsWith('https://')) {
1152
+ if (!url.startsWith('https://') && !url.startsWith('http://') /* <- Note: [👣] */) {
1204
1153
  return false;
1205
1154
  }
1206
1155
  if (url.includes('#')) {
1207
1156
  // TODO: [🐠]
1208
1157
  return false;
1209
1158
  }
1159
+ /*
1160
+ Note: [👣][🧠] Is it secure to allow pipeline URLs on private and unsecured networks?
1210
1161
  if (isUrlOnPrivateNetwork(url)) {
1211
1162
  return false;
1212
1163
  }
1164
+ */
1213
1165
  return true;
1214
1166
  }
1215
1167
  /**
@@ -11289,13 +11241,13 @@ function createCollectionFromPromise(promptbookSourcesPromiseOrFactory) {
11289
11241
  *
11290
11242
  * Note: Works only in Node.js environment because it reads the file system
11291
11243
  *
11292
- * @param path - path to the directory with pipelines
11244
+ * @param rootPath - path to the directory with pipelines
11293
11245
  * @param tools - Execution tools to be used for pipeline preparation if needed - If not provided, `$provideExecutionToolsForNode` will be used
11294
11246
  * @param options - Options for the collection creation
11295
11247
  * @returns PipelineCollection
11296
11248
  * @public exported from `@promptbook/node`
11297
11249
  */
11298
- function createCollectionFromDirectory(path, tools, options) {
11250
+ function createCollectionFromDirectory(rootPath, tools, options) {
11299
11251
  return __awaiter(this, void 0, void 0, function () {
11300
11252
  var madeLibraryFilePath, _a, _b, isRecursive, _c, isVerbose, _d, isLazyLoaded, _e, isCrashedOnError, rootUrl, collection;
11301
11253
  var _this = this;
@@ -11312,7 +11264,7 @@ function createCollectionFromDirectory(path, tools, options) {
11312
11264
  throw new EnvironmentMismatchError('Can not create collection without filesystem tools');
11313
11265
  // <- TODO: [🧠] What is the best error type here`
11314
11266
  }
11315
- madeLibraryFilePath = join(path, "".concat(DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME
11267
+ madeLibraryFilePath = join(rootPath, "".concat(DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME
11316
11268
  // <- TODO: [🦒] Allow to override (pass different value into the function)
11317
11269
  , ".json"));
11318
11270
  return [4 /*yield*/, isFileExisting(madeLibraryFilePath, tools.fs)];
@@ -11331,18 +11283,18 @@ function createCollectionFromDirectory(path, tools, options) {
11331
11283
  switch (_b.label) {
11332
11284
  case 0:
11333
11285
  if (isVerbose) {
11334
- console.info(colors.cyan("Creating pipeline collection from path ".concat(path.split('\\').join('/'))));
11286
+ console.info(colors.cyan("Creating pipeline collection from path ".concat(rootPath.split('\\').join('/'))));
11335
11287
  }
11336
- return [4 /*yield*/, listAllFiles(path, isRecursive, tools.fs)];
11288
+ return [4 /*yield*/, listAllFiles(rootPath, isRecursive, tools.fs)];
11337
11289
  case 1:
11338
11290
  fileNames = _b.sent();
11339
- // Note: First load all .book.json and then .book.md files
11340
- // .book.json can be prepared so it is faster to load
11291
+ // Note: First load all `.book.json` and then `.book` / `.book.md` files
11292
+ // `.book.json` can be prepared so it is faster to load
11341
11293
  fileNames.sort(function (a, b) {
11342
- if (a.endsWith('.json') && b.endsWith('.md')) {
11294
+ if (a.endsWith('.json') && (b.endsWith('.book') || b.endsWith('.book.md'))) {
11343
11295
  return -1;
11344
11296
  }
11345
- if (a.endsWith('.md') && b.endsWith('.json')) {
11297
+ if ((a.endsWith('.book') || a.endsWith('.book.md')) && b.endsWith('.json')) {
11346
11298
  return 1;
11347
11299
  }
11348
11300
  return 0;
@@ -11359,7 +11311,7 @@ function createCollectionFromDirectory(path, tools, options) {
11359
11311
  case 1:
11360
11312
  _f.trys.push([1, 8, , 9]);
11361
11313
  pipeline = null;
11362
- if (!fileName.endsWith('.book.md')) return [3 /*break*/, 4];
11314
+ if (!(fileName.endsWith('.book') || fileName.endsWith('.book.md'))) return [3 /*break*/, 4];
11363
11315
  _c = validatePipelineString;
11364
11316
  return [4 /*yield*/, readFile(fileName, 'utf-8')];
11365
11317
  case 2:
@@ -11391,7 +11343,8 @@ function createCollectionFromDirectory(path, tools, options) {
11391
11343
  if (pipeline !== null) {
11392
11344
  if (rootUrl !== undefined) {
11393
11345
  if (pipeline.pipelineUrl === undefined) {
11394
- pipelineUrl = rootUrl + '/' + fileName.split('\\').join('/');
11346
+ pipelineUrl = rootUrl + '/' + relative(rootPath, fileName).split('\\').join('/');
11347
+ // console.log({ pipelineUrl, rootPath, rootUrl, fileName });
11395
11348
  if (isVerbose) {
11396
11349
  console.info(colors.yellow("Implicitly set pipeline URL to ".concat(pipelineUrl, " from ").concat(fileName
11397
11350
  .split('\\')