@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.
|
@@ -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
|
|
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(
|
|
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
package/umd/index.umd.js
CHANGED
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
* @generated
|
|
54
54
|
* @see https://github.com/webgptorg/promptbook
|
|
55
55
|
*/
|
|
56
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.85.0-
|
|
56
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.85.0-12';
|
|
57
57
|
/**
|
|
58
58
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
59
59
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -4069,57 +4069,6 @@
|
|
|
4069
4069
|
return true;
|
|
4070
4070
|
}
|
|
4071
4071
|
|
|
4072
|
-
/**
|
|
4073
|
-
* Checks if an URL is reserved for private networks or localhost.
|
|
4074
|
-
*
|
|
4075
|
-
* Note: There are two simmilar functions:
|
|
4076
|
-
* - `isUrlOnPrivateNetwork` which tests full URL
|
|
4077
|
-
* - `isHostnameOnPrivateNetwork` *(this one)* which tests just hostname
|
|
4078
|
-
*
|
|
4079
|
-
* @public exported from `@promptbook/utils`
|
|
4080
|
-
*/
|
|
4081
|
-
function isHostnameOnPrivateNetwork(hostname) {
|
|
4082
|
-
if (hostname === 'example.com' ||
|
|
4083
|
-
hostname === 'localhost' ||
|
|
4084
|
-
hostname.endsWith('.localhost') ||
|
|
4085
|
-
hostname.endsWith('.local') ||
|
|
4086
|
-
hostname.endsWith('.test') ||
|
|
4087
|
-
hostname === '127.0.0.1' ||
|
|
4088
|
-
hostname === '::1') {
|
|
4089
|
-
return true;
|
|
4090
|
-
}
|
|
4091
|
-
if (hostname.includes(':')) {
|
|
4092
|
-
// IPv6
|
|
4093
|
-
var ipParts = hostname.split(':');
|
|
4094
|
-
return ipParts[0] === 'fc00' || ipParts[0] === 'fd00' || ipParts[0] === 'fe80';
|
|
4095
|
-
}
|
|
4096
|
-
else {
|
|
4097
|
-
// IPv4
|
|
4098
|
-
var ipParts = hostname.split('.').map(function (part) { return Number.parseInt(part, 10); });
|
|
4099
|
-
return (ipParts[0] === 10 ||
|
|
4100
|
-
(ipParts[0] === 172 && ipParts[1] >= 16 && ipParts[1] <= 31) ||
|
|
4101
|
-
(ipParts[0] === 192 && ipParts[1] === 168));
|
|
4102
|
-
}
|
|
4103
|
-
}
|
|
4104
|
-
|
|
4105
|
-
/**
|
|
4106
|
-
* Checks if an IP address or hostname is reserved for private networks or localhost.
|
|
4107
|
-
*
|
|
4108
|
-
* Note: There are two simmilar functions:
|
|
4109
|
-
* - `isUrlOnPrivateNetwork` *(this one)* which tests full URL
|
|
4110
|
-
* - `isHostnameOnPrivateNetwork` which tests just hostname
|
|
4111
|
-
*
|
|
4112
|
-
* @param {string} ipAddress - The IP address to check.
|
|
4113
|
-
* @returns {boolean} Returns true if the IP address is reserved for private networks or localhost, otherwise false.
|
|
4114
|
-
* @public exported from `@promptbook/utils`
|
|
4115
|
-
*/
|
|
4116
|
-
function isUrlOnPrivateNetwork(url) {
|
|
4117
|
-
if (typeof url === 'string') {
|
|
4118
|
-
url = new URL(url);
|
|
4119
|
-
}
|
|
4120
|
-
return isHostnameOnPrivateNetwork(url.hostname);
|
|
4121
|
-
}
|
|
4122
|
-
|
|
4123
4072
|
/**
|
|
4124
4073
|
* Tests if given string is valid pipeline URL URL.
|
|
4125
4074
|
*
|
|
@@ -4133,16 +4082,19 @@
|
|
|
4133
4082
|
if (!isValidUrl(url)) {
|
|
4134
4083
|
return false;
|
|
4135
4084
|
}
|
|
4136
|
-
if (!url.startsWith('https://')) {
|
|
4085
|
+
if (!url.startsWith('https://') && !url.startsWith('http://') /* <- Note: [👣] */) {
|
|
4137
4086
|
return false;
|
|
4138
4087
|
}
|
|
4139
4088
|
if (url.includes('#')) {
|
|
4140
4089
|
// TODO: [🐠]
|
|
4141
4090
|
return false;
|
|
4142
4091
|
}
|
|
4092
|
+
/*
|
|
4093
|
+
Note: [👣][🧠] Is it secure to allow pipeline URLs on private and unsecured networks?
|
|
4143
4094
|
if (isUrlOnPrivateNetwork(url)) {
|
|
4144
4095
|
return false;
|
|
4145
4096
|
}
|
|
4097
|
+
*/
|
|
4146
4098
|
return true;
|
|
4147
4099
|
}
|
|
4148
4100
|
/**
|
|
@@ -12039,13 +11991,13 @@
|
|
|
12039
11991
|
*
|
|
12040
11992
|
* Note: Works only in Node.js environment because it reads the file system
|
|
12041
11993
|
*
|
|
12042
|
-
* @param
|
|
11994
|
+
* @param rootPath - path to the directory with pipelines
|
|
12043
11995
|
* @param tools - Execution tools to be used for pipeline preparation if needed - If not provided, `$provideExecutionToolsForNode` will be used
|
|
12044
11996
|
* @param options - Options for the collection creation
|
|
12045
11997
|
* @returns PipelineCollection
|
|
12046
11998
|
* @public exported from `@promptbook/node`
|
|
12047
11999
|
*/
|
|
12048
|
-
function createCollectionFromDirectory(
|
|
12000
|
+
function createCollectionFromDirectory(rootPath, tools, options) {
|
|
12049
12001
|
return __awaiter(this, void 0, void 0, function () {
|
|
12050
12002
|
var madeLibraryFilePath, _a, _b, isRecursive, _c, isVerbose, _d, isLazyLoaded, _e, isCrashedOnError, rootUrl, collection;
|
|
12051
12003
|
var _this = this;
|
|
@@ -12062,7 +12014,7 @@
|
|
|
12062
12014
|
throw new EnvironmentMismatchError('Can not create collection without filesystem tools');
|
|
12063
12015
|
// <- TODO: [🧠] What is the best error type here`
|
|
12064
12016
|
}
|
|
12065
|
-
madeLibraryFilePath = path.join(
|
|
12017
|
+
madeLibraryFilePath = path.join(rootPath, "".concat(DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME
|
|
12066
12018
|
// <- TODO: [🦒] Allow to override (pass different value into the function)
|
|
12067
12019
|
, ".json"));
|
|
12068
12020
|
return [4 /*yield*/, isFileExisting(madeLibraryFilePath, tools.fs)];
|
|
@@ -12081,18 +12033,18 @@
|
|
|
12081
12033
|
switch (_b.label) {
|
|
12082
12034
|
case 0:
|
|
12083
12035
|
if (isVerbose) {
|
|
12084
|
-
console.info(colors__default["default"].cyan("Creating pipeline collection from path ".concat(
|
|
12036
|
+
console.info(colors__default["default"].cyan("Creating pipeline collection from path ".concat(rootPath.split('\\').join('/'))));
|
|
12085
12037
|
}
|
|
12086
|
-
return [4 /*yield*/, listAllFiles(
|
|
12038
|
+
return [4 /*yield*/, listAllFiles(rootPath, isRecursive, tools.fs)];
|
|
12087
12039
|
case 1:
|
|
12088
12040
|
fileNames = _b.sent();
|
|
12089
|
-
// Note: First load all
|
|
12090
|
-
//
|
|
12041
|
+
// Note: First load all `.book.json` and then `.book` / `.book.md` files
|
|
12042
|
+
// `.book.json` can be prepared so it is faster to load
|
|
12091
12043
|
fileNames.sort(function (a, b) {
|
|
12092
|
-
if (a.endsWith('.json') && b.endsWith('.md')) {
|
|
12044
|
+
if (a.endsWith('.json') && (b.endsWith('.book') || b.endsWith('.book.md'))) {
|
|
12093
12045
|
return -1;
|
|
12094
12046
|
}
|
|
12095
|
-
if (a.endsWith('.md') && b.endsWith('.json')) {
|
|
12047
|
+
if ((a.endsWith('.book') || a.endsWith('.book.md')) && b.endsWith('.json')) {
|
|
12096
12048
|
return 1;
|
|
12097
12049
|
}
|
|
12098
12050
|
return 0;
|
|
@@ -12109,7 +12061,7 @@
|
|
|
12109
12061
|
case 1:
|
|
12110
12062
|
_f.trys.push([1, 8, , 9]);
|
|
12111
12063
|
pipeline = null;
|
|
12112
|
-
if (!fileName.endsWith('.book.md')) return [3 /*break*/, 4];
|
|
12064
|
+
if (!(fileName.endsWith('.book') || fileName.endsWith('.book.md'))) return [3 /*break*/, 4];
|
|
12113
12065
|
_c = validatePipelineString;
|
|
12114
12066
|
return [4 /*yield*/, promises.readFile(fileName, 'utf-8')];
|
|
12115
12067
|
case 2:
|
|
@@ -12141,7 +12093,8 @@
|
|
|
12141
12093
|
if (pipeline !== null) {
|
|
12142
12094
|
if (rootUrl !== undefined) {
|
|
12143
12095
|
if (pipeline.pipelineUrl === undefined) {
|
|
12144
|
-
pipelineUrl = rootUrl + '/' + fileName.split('\\').join('/');
|
|
12096
|
+
pipelineUrl = rootUrl + '/' + path.relative(rootPath, fileName).split('\\').join('/');
|
|
12097
|
+
// console.log({ pipelineUrl, rootPath, rootUrl, fileName });
|
|
12145
12098
|
if (isVerbose) {
|
|
12146
12099
|
console.info(colors__default["default"].yellow("Implicitly set pipeline URL to ".concat(pipelineUrl, " from ").concat(fileName
|
|
12147
12100
|
.split('\\')
|