@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.
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-7';
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
  /**
@@ -2044,18 +1996,16 @@ function assertsTaskSuccessful(executionResult) {
2044
1996
  */
2045
1997
  function createTask(options) {
2046
1998
  var taskType = options.taskType, taskProcessCallback = options.taskProcessCallback;
2047
- var taskId = "".concat(taskType.toLowerCase().substring(0, 4), "-").concat($randomToken(8 /* <- TODO: !!! To global config + Use Base58 to avoid simmilar char conflicts */));
1999
+ var taskId = "".concat(taskType.toLowerCase().substring(0, 4), "-").concat($randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */));
2048
2000
  var partialResultSubject = new BehaviorSubject({});
2049
2001
  var finalResultPromise = /* not await */ taskProcessCallback(function (newOngoingResult) {
2050
2002
  partialResultSubject.next(newOngoingResult);
2051
2003
  });
2052
2004
  finalResultPromise
2053
2005
  .catch(function (error) {
2054
- // console.error('!!!!! Task failed:', error);
2055
2006
  partialResultSubject.error(error);
2056
2007
  })
2057
2008
  .then(function (value) {
2058
- // console.error('!!!!! Task finished:', value);
2059
2009
  if (value) {
2060
2010
  try {
2061
2011
  assertsTaskSuccessful(value);
@@ -2077,9 +2027,7 @@ function createTask(options) {
2077
2027
  return [4 /*yield*/, finalResultPromise];
2078
2028
  case 1:
2079
2029
  finalResult = _b.sent();
2080
- console.error('!!!!! finalResult:', finalResult);
2081
2030
  if (isCrashedOnError) {
2082
- console.error('!!!!! isCrashedOnError:', finalResult);
2083
2031
  assertsTaskSuccessful(finalResult);
2084
2032
  }
2085
2033
  return [2 /*return*/, finalResult];
@@ -11293,13 +11241,13 @@ function createCollectionFromPromise(promptbookSourcesPromiseOrFactory) {
11293
11241
  *
11294
11242
  * Note: Works only in Node.js environment because it reads the file system
11295
11243
  *
11296
- * @param path - path to the directory with pipelines
11244
+ * @param rootPath - path to the directory with pipelines
11297
11245
  * @param tools - Execution tools to be used for pipeline preparation if needed - If not provided, `$provideExecutionToolsForNode` will be used
11298
11246
  * @param options - Options for the collection creation
11299
11247
  * @returns PipelineCollection
11300
11248
  * @public exported from `@promptbook/node`
11301
11249
  */
11302
- function createCollectionFromDirectory(path, tools, options) {
11250
+ function createCollectionFromDirectory(rootPath, tools, options) {
11303
11251
  return __awaiter(this, void 0, void 0, function () {
11304
11252
  var madeLibraryFilePath, _a, _b, isRecursive, _c, isVerbose, _d, isLazyLoaded, _e, isCrashedOnError, rootUrl, collection;
11305
11253
  var _this = this;
@@ -11316,7 +11264,7 @@ function createCollectionFromDirectory(path, tools, options) {
11316
11264
  throw new EnvironmentMismatchError('Can not create collection without filesystem tools');
11317
11265
  // <- TODO: [🧠] What is the best error type here`
11318
11266
  }
11319
- madeLibraryFilePath = join(path, "".concat(DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME
11267
+ madeLibraryFilePath = join(rootPath, "".concat(DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME
11320
11268
  // <- TODO: [🦒] Allow to override (pass different value into the function)
11321
11269
  , ".json"));
11322
11270
  return [4 /*yield*/, isFileExisting(madeLibraryFilePath, tools.fs)];
@@ -11335,18 +11283,18 @@ function createCollectionFromDirectory(path, tools, options) {
11335
11283
  switch (_b.label) {
11336
11284
  case 0:
11337
11285
  if (isVerbose) {
11338
- 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('/'))));
11339
11287
  }
11340
- return [4 /*yield*/, listAllFiles(path, isRecursive, tools.fs)];
11288
+ return [4 /*yield*/, listAllFiles(rootPath, isRecursive, tools.fs)];
11341
11289
  case 1:
11342
11290
  fileNames = _b.sent();
11343
- // Note: First load all .book.json and then .book.md files
11344
- // .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
11345
11293
  fileNames.sort(function (a, b) {
11346
- if (a.endsWith('.json') && b.endsWith('.md')) {
11294
+ if (a.endsWith('.json') && (b.endsWith('.book') || b.endsWith('.book.md'))) {
11347
11295
  return -1;
11348
11296
  }
11349
- if (a.endsWith('.md') && b.endsWith('.json')) {
11297
+ if ((a.endsWith('.book') || a.endsWith('.book.md')) && b.endsWith('.json')) {
11350
11298
  return 1;
11351
11299
  }
11352
11300
  return 0;
@@ -11363,7 +11311,7 @@ function createCollectionFromDirectory(path, tools, options) {
11363
11311
  case 1:
11364
11312
  _f.trys.push([1, 8, , 9]);
11365
11313
  pipeline = null;
11366
- if (!fileName.endsWith('.book.md')) return [3 /*break*/, 4];
11314
+ if (!(fileName.endsWith('.book') || fileName.endsWith('.book.md'))) return [3 /*break*/, 4];
11367
11315
  _c = validatePipelineString;
11368
11316
  return [4 /*yield*/, readFile(fileName, 'utf-8')];
11369
11317
  case 2:
@@ -11395,7 +11343,8 @@ function createCollectionFromDirectory(path, tools, options) {
11395
11343
  if (pipeline !== null) {
11396
11344
  if (rootUrl !== undefined) {
11397
11345
  if (pipeline.pipelineUrl === undefined) {
11398
- pipelineUrl = rootUrl + '/' + fileName.split('\\').join('/');
11346
+ pipelineUrl = rootUrl + '/' + relative(rootPath, fileName).split('\\').join('/');
11347
+ // console.log({ pipelineUrl, rootPath, rootUrl, fileName });
11399
11348
  if (isVerbose) {
11400
11349
  console.info(colors.yellow("Implicitly set pipeline URL to ".concat(pipelineUrl, " from ").concat(fileName
11401
11350
  .split('\\')