@promptbook/cli 0.85.0-11 → 0.85.0-13
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/esm/index.es.js
CHANGED
|
@@ -2,7 +2,7 @@ import colors from 'colors';
|
|
|
2
2
|
import commander from 'commander';
|
|
3
3
|
import spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
|
|
4
4
|
import { forTime, forEver } from 'waitasecond';
|
|
5
|
-
import { basename, join, dirname } from 'path';
|
|
5
|
+
import { basename, join, dirname, relative } from 'path';
|
|
6
6
|
import { stat, access, constants, readFile, writeFile, readdir, mkdir, unlink, rm, rmdir, rename } from 'fs/promises';
|
|
7
7
|
import hexEncoder from 'crypto-js/enc-hex';
|
|
8
8
|
import sha256 from 'crypto-js/sha256';
|
|
@@ -43,7 +43,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
43
43
|
* @generated
|
|
44
44
|
* @see https://github.com/webgptorg/promptbook
|
|
45
45
|
*/
|
|
46
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.85.0-
|
|
46
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.85.0-12';
|
|
47
47
|
/**
|
|
48
48
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
49
49
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -4059,57 +4059,6 @@ function isValidPromptbookVersion(version) {
|
|
|
4059
4059
|
return true;
|
|
4060
4060
|
}
|
|
4061
4061
|
|
|
4062
|
-
/**
|
|
4063
|
-
* Checks if an URL is reserved for private networks or localhost.
|
|
4064
|
-
*
|
|
4065
|
-
* Note: There are two simmilar functions:
|
|
4066
|
-
* - `isUrlOnPrivateNetwork` which tests full URL
|
|
4067
|
-
* - `isHostnameOnPrivateNetwork` *(this one)* which tests just hostname
|
|
4068
|
-
*
|
|
4069
|
-
* @public exported from `@promptbook/utils`
|
|
4070
|
-
*/
|
|
4071
|
-
function isHostnameOnPrivateNetwork(hostname) {
|
|
4072
|
-
if (hostname === 'example.com' ||
|
|
4073
|
-
hostname === 'localhost' ||
|
|
4074
|
-
hostname.endsWith('.localhost') ||
|
|
4075
|
-
hostname.endsWith('.local') ||
|
|
4076
|
-
hostname.endsWith('.test') ||
|
|
4077
|
-
hostname === '127.0.0.1' ||
|
|
4078
|
-
hostname === '::1') {
|
|
4079
|
-
return true;
|
|
4080
|
-
}
|
|
4081
|
-
if (hostname.includes(':')) {
|
|
4082
|
-
// IPv6
|
|
4083
|
-
var ipParts = hostname.split(':');
|
|
4084
|
-
return ipParts[0] === 'fc00' || ipParts[0] === 'fd00' || ipParts[0] === 'fe80';
|
|
4085
|
-
}
|
|
4086
|
-
else {
|
|
4087
|
-
// IPv4
|
|
4088
|
-
var ipParts = hostname.split('.').map(function (part) { return Number.parseInt(part, 10); });
|
|
4089
|
-
return (ipParts[0] === 10 ||
|
|
4090
|
-
(ipParts[0] === 172 && ipParts[1] >= 16 && ipParts[1] <= 31) ||
|
|
4091
|
-
(ipParts[0] === 192 && ipParts[1] === 168));
|
|
4092
|
-
}
|
|
4093
|
-
}
|
|
4094
|
-
|
|
4095
|
-
/**
|
|
4096
|
-
* Checks if an IP address or hostname is reserved for private networks or localhost.
|
|
4097
|
-
*
|
|
4098
|
-
* Note: There are two simmilar functions:
|
|
4099
|
-
* - `isUrlOnPrivateNetwork` *(this one)* which tests full URL
|
|
4100
|
-
* - `isHostnameOnPrivateNetwork` which tests just hostname
|
|
4101
|
-
*
|
|
4102
|
-
* @param {string} ipAddress - The IP address to check.
|
|
4103
|
-
* @returns {boolean} Returns true if the IP address is reserved for private networks or localhost, otherwise false.
|
|
4104
|
-
* @public exported from `@promptbook/utils`
|
|
4105
|
-
*/
|
|
4106
|
-
function isUrlOnPrivateNetwork(url) {
|
|
4107
|
-
if (typeof url === 'string') {
|
|
4108
|
-
url = new URL(url);
|
|
4109
|
-
}
|
|
4110
|
-
return isHostnameOnPrivateNetwork(url.hostname);
|
|
4111
|
-
}
|
|
4112
|
-
|
|
4113
4062
|
/**
|
|
4114
4063
|
* Tests if given string is valid pipeline URL URL.
|
|
4115
4064
|
*
|
|
@@ -4123,16 +4072,19 @@ function isValidPipelineUrl(url) {
|
|
|
4123
4072
|
if (!isValidUrl(url)) {
|
|
4124
4073
|
return false;
|
|
4125
4074
|
}
|
|
4126
|
-
if (!url.startsWith('https://')) {
|
|
4075
|
+
if (!url.startsWith('https://') && !url.startsWith('http://') /* <- Note: [👣] */) {
|
|
4127
4076
|
return false;
|
|
4128
4077
|
}
|
|
4129
4078
|
if (url.includes('#')) {
|
|
4130
4079
|
// TODO: [🐠]
|
|
4131
4080
|
return false;
|
|
4132
4081
|
}
|
|
4082
|
+
/*
|
|
4083
|
+
Note: [👣][🧠] Is it secure to allow pipeline URLs on private and unsecured networks?
|
|
4133
4084
|
if (isUrlOnPrivateNetwork(url)) {
|
|
4134
4085
|
return false;
|
|
4135
4086
|
}
|
|
4087
|
+
*/
|
|
4136
4088
|
return true;
|
|
4137
4089
|
}
|
|
4138
4090
|
/**
|
|
@@ -12029,13 +11981,13 @@ function createCollectionFromPromise(promptbookSourcesPromiseOrFactory) {
|
|
|
12029
11981
|
*
|
|
12030
11982
|
* Note: Works only in Node.js environment because it reads the file system
|
|
12031
11983
|
*
|
|
12032
|
-
* @param
|
|
11984
|
+
* @param rootPath - path to the directory with pipelines
|
|
12033
11985
|
* @param tools - Execution tools to be used for pipeline preparation if needed - If not provided, `$provideExecutionToolsForNode` will be used
|
|
12034
11986
|
* @param options - Options for the collection creation
|
|
12035
11987
|
* @returns PipelineCollection
|
|
12036
11988
|
* @public exported from `@promptbook/node`
|
|
12037
11989
|
*/
|
|
12038
|
-
function createCollectionFromDirectory(
|
|
11990
|
+
function createCollectionFromDirectory(rootPath, tools, options) {
|
|
12039
11991
|
return __awaiter(this, void 0, void 0, function () {
|
|
12040
11992
|
var madeLibraryFilePath, _a, _b, isRecursive, _c, isVerbose, _d, isLazyLoaded, _e, isCrashedOnError, rootUrl, collection;
|
|
12041
11993
|
var _this = this;
|
|
@@ -12052,7 +12004,7 @@ function createCollectionFromDirectory(path, tools, options) {
|
|
|
12052
12004
|
throw new EnvironmentMismatchError('Can not create collection without filesystem tools');
|
|
12053
12005
|
// <- TODO: [🧠] What is the best error type here`
|
|
12054
12006
|
}
|
|
12055
|
-
madeLibraryFilePath = join(
|
|
12007
|
+
madeLibraryFilePath = join(rootPath, "".concat(DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME
|
|
12056
12008
|
// <- TODO: [🦒] Allow to override (pass different value into the function)
|
|
12057
12009
|
, ".json"));
|
|
12058
12010
|
return [4 /*yield*/, isFileExisting(madeLibraryFilePath, tools.fs)];
|
|
@@ -12071,18 +12023,18 @@ function createCollectionFromDirectory(path, tools, options) {
|
|
|
12071
12023
|
switch (_b.label) {
|
|
12072
12024
|
case 0:
|
|
12073
12025
|
if (isVerbose) {
|
|
12074
|
-
console.info(colors.cyan("Creating pipeline collection from path ".concat(
|
|
12026
|
+
console.info(colors.cyan("Creating pipeline collection from path ".concat(rootPath.split('\\').join('/'))));
|
|
12075
12027
|
}
|
|
12076
|
-
return [4 /*yield*/, listAllFiles(
|
|
12028
|
+
return [4 /*yield*/, listAllFiles(rootPath, isRecursive, tools.fs)];
|
|
12077
12029
|
case 1:
|
|
12078
12030
|
fileNames = _b.sent();
|
|
12079
|
-
// Note: First load all
|
|
12080
|
-
//
|
|
12031
|
+
// Note: First load all `.book.json` and then `.book` / `.book.md` files
|
|
12032
|
+
// `.book.json` can be prepared so it is faster to load
|
|
12081
12033
|
fileNames.sort(function (a, b) {
|
|
12082
|
-
if (a.endsWith('.json') && b.endsWith('.md')) {
|
|
12034
|
+
if (a.endsWith('.json') && (b.endsWith('.book') || b.endsWith('.book.md'))) {
|
|
12083
12035
|
return -1;
|
|
12084
12036
|
}
|
|
12085
|
-
if (a.endsWith('.md') && b.endsWith('.json')) {
|
|
12037
|
+
if ((a.endsWith('.book') || a.endsWith('.book.md')) && b.endsWith('.json')) {
|
|
12086
12038
|
return 1;
|
|
12087
12039
|
}
|
|
12088
12040
|
return 0;
|
|
@@ -12099,7 +12051,7 @@ function createCollectionFromDirectory(path, tools, options) {
|
|
|
12099
12051
|
case 1:
|
|
12100
12052
|
_f.trys.push([1, 8, , 9]);
|
|
12101
12053
|
pipeline = null;
|
|
12102
|
-
if (!fileName.endsWith('.book.md')) return [3 /*break*/, 4];
|
|
12054
|
+
if (!(fileName.endsWith('.book') || fileName.endsWith('.book.md'))) return [3 /*break*/, 4];
|
|
12103
12055
|
_c = validatePipelineString;
|
|
12104
12056
|
return [4 /*yield*/, readFile(fileName, 'utf-8')];
|
|
12105
12057
|
case 2:
|
|
@@ -12131,7 +12083,8 @@ function createCollectionFromDirectory(path, tools, options) {
|
|
|
12131
12083
|
if (pipeline !== null) {
|
|
12132
12084
|
if (rootUrl !== undefined) {
|
|
12133
12085
|
if (pipeline.pipelineUrl === undefined) {
|
|
12134
|
-
pipelineUrl = rootUrl + '/' + fileName.split('\\').join('/');
|
|
12086
|
+
pipelineUrl = rootUrl + '/' + relative(rootPath, fileName).split('\\').join('/');
|
|
12087
|
+
// console.log({ pipelineUrl, rootPath, rootUrl, fileName });
|
|
12135
12088
|
if (isVerbose) {
|
|
12136
12089
|
console.info(colors.yellow("Implicitly set pipeline URL to ".concat(pipelineUrl, " from ").concat(fileName
|
|
12137
12090
|
.split('\\')
|