@promptbook/cli 0.85.0-4 → 0.85.0-5

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.
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import type fs from 'node:fs/promises';
2
+ import type fs from 'fs/promises';
3
3
  /**
4
4
  * Container for all the tools needed to manipulate with filesystem
5
5
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/cli",
3
- "version": "0.85.0-4",
3
+ "version": "0.85.0-5",
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,
package/umd/index.umd.js CHANGED
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('commander'), require('spacetrim'), require('waitasecond'), require('node:path'), require('node:fs/promises'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('dotenv'), require('node:child_process'), require('prettier'), require('prettier/parser-html'), require('rxjs'), require('crypto'), require('papaparse'), require('crypto-js'), require('mime-types'), require('glob-promise'), require('prompts'), require('moment'), require('express'), require('node:http'), require('socket.io'), require('socket.io-client'), require('@anthropic-ai/sdk'), require('@azure/openai'), require('openai'), require('@mozilla/readability'), require('jsdom'), require('showdown')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'colors', 'commander', 'spacetrim', 'waitasecond', 'node:path', 'node:fs/promises', 'crypto-js/enc-hex', 'crypto-js/sha256', 'dotenv', 'node:child_process', 'prettier', 'prettier/parser-html', 'rxjs', 'crypto', 'papaparse', 'crypto-js', 'mime-types', 'glob-promise', 'prompts', 'moment', 'express', 'node:http', 'socket.io', 'socket.io-client', '@anthropic-ai/sdk', '@azure/openai', 'openai', '@mozilla/readability', 'jsdom', 'showdown'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-cli"] = {}, global.colors, global.commander, global.spaceTrim, global.waitasecond, global.node_path, global.promises, global.hexEncoder, global.sha256, global.dotenv, global.node_child_process, global.prettier, global.parserHtml, global.rxjs, global.crypto, global.papaparse, global.cryptoJs, global.mimeTypes, global.glob, global.prompts, global.moment, global.express, global.http, global.socket_io, global.socket_ioClient, global.Anthropic, global.openai, global.OpenAI, global.readability, global.jsdom, global.showdown));
5
- })(this, (function (exports, colors, commander, spaceTrim, waitasecond, node_path, promises, hexEncoder, sha256, dotenv, node_child_process, prettier, parserHtml, rxjs, crypto, papaparse, cryptoJs, mimeTypes, glob, prompts, moment, express, http, socket_io, socket_ioClient, Anthropic, openai, OpenAI, readability, jsdom, showdown) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('commander'), require('spacetrim'), require('waitasecond'), require('path'), require('fs/promises'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('dotenv'), require('child_process'), require('prettier'), require('prettier/parser-html'), require('rxjs'), require('crypto'), require('papaparse'), require('crypto-js'), require('mime-types'), require('glob-promise'), require('prompts'), require('moment'), require('express'), require('http'), require('socket.io'), require('socket.io-client'), require('@anthropic-ai/sdk'), require('@azure/openai'), require('openai'), require('@mozilla/readability'), require('jsdom'), require('showdown')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'colors', 'commander', 'spacetrim', 'waitasecond', 'path', 'fs/promises', 'crypto-js/enc-hex', 'crypto-js/sha256', 'dotenv', 'child_process', 'prettier', 'prettier/parser-html', 'rxjs', 'crypto', 'papaparse', 'crypto-js', 'mime-types', 'glob-promise', 'prompts', 'moment', 'express', 'http', 'socket.io', 'socket.io-client', '@anthropic-ai/sdk', '@azure/openai', 'openai', '@mozilla/readability', 'jsdom', 'showdown'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-cli"] = {}, global.colors, global.commander, global.spaceTrim, global.waitasecond, global.path, global.promises, global.hexEncoder, global.sha256, global.dotenv, global.child_process, global.prettier, global.parserHtml, global.rxjs, global.crypto, global.papaparse, global.cryptoJs, global.mimeTypes, global.glob, global.prompts, global.moment, global.express, global.http, global.socket_io, global.socket_ioClient, global.Anthropic, global.openai, global.OpenAI, global.readability, global.jsdom, global.showdown));
5
+ })(this, (function (exports, colors, commander, spaceTrim, waitasecond, path, promises, hexEncoder, sha256, dotenv, child_process, prettier, parserHtml, rxjs, crypto, papaparse, cryptoJs, mimeTypes, glob, prompts, moment, express, http, socket_io, socket_ioClient, Anthropic, openai, OpenAI, readability, jsdom, showdown) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -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-3';
56
+ var PROMPTBOOK_ENGINE_VERSION = '0.85.0-4';
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
@@ -1477,7 +1477,7 @@
1477
1477
  value = value.replace(/\.html$/, '');
1478
1478
  }
1479
1479
  else if (isValidFilePath(value)) {
1480
- value = node_path.basename(value);
1480
+ value = path.basename(value);
1481
1481
  // Note: Keeping extension in the name
1482
1482
  }
1483
1483
  value = value.split('/').join('-');
@@ -1517,7 +1517,7 @@
1517
1517
  var name = titleToName(key);
1518
1518
  var hash = sha256__default["default"](hexEncoder__default["default"].parse(name)).toString( /* hex */);
1519
1519
  // <- TODO: [🥬] Encapsulate sha256 to some private utility function
1520
- return node_path.join.apply(void 0, __spreadArray(__spreadArray([this.options.rootFolderPath], __read(nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */)), false), ["".concat(name.substring(0, MAX_FILENAME_LENGTH), ".json")], false));
1520
+ return path.join.apply(void 0, __spreadArray(__spreadArray([this.options.rootFolderPath], __read(nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */)), false), ["".concat(name.substring(0, MAX_FILENAME_LENGTH), ".json")], false));
1521
1521
  };
1522
1522
  /**
1523
1523
  * @@@ Returns the current value associated with the given key, or null if the given key does not exist in the list associated with the object.
@@ -1558,7 +1558,7 @@
1558
1558
  throw new UnexpectedError("The \"".concat(key, "\" you want to store in JSON file is not serializable as JSON"));
1559
1559
  }
1560
1560
  fileContent = stringifyPipelineJson(value);
1561
- return [4 /*yield*/, promises.mkdir(node_path.dirname(filename), { recursive: true })];
1561
+ return [4 /*yield*/, promises.mkdir(path.dirname(filename), { recursive: true })];
1562
1562
  case 1:
1563
1563
  _a.sent(); // <- [0]
1564
1564
  return [4 /*yield*/, promises.writeFile(filename, fileContent, 'utf-8')];
@@ -2416,7 +2416,7 @@
2416
2416
  case 3:
2417
2417
  if (!!envFilePatterns_1_1.done) return [3 /*break*/, 6];
2418
2418
  pattern = envFilePatterns_1_1.value;
2419
- envFilename = node_path.join(rootDirname, pattern);
2419
+ envFilename = path.join(rootDirname, pattern);
2420
2420
  return [4 /*yield*/, isFileExisting(envFilename, $provideFilesystemForNode())];
2421
2421
  case 4:
2422
2422
  if (_b.sent()) {
@@ -2444,7 +2444,7 @@
2444
2444
  return [3 /*break*/, 11];
2445
2445
  }
2446
2446
  // Note: If the directory does not exist, try the parent directory
2447
- rootDirname = node_path.join(rootDirname, '..');
2447
+ rootDirname = path.join(rootDirname, '..');
2448
2448
  _b.label = 10;
2449
2449
  case 10:
2450
2450
  i++;
@@ -2874,7 +2874,7 @@
2874
2874
  _c.sent()]),
2875
2875
  {
2876
2876
  storage: new FileCacheStorage({ fs: $provideFilesystemForNode() }, {
2877
- rootFolderPath: node_path.join(process.cwd(), DEFAULT_EXECUTION_CACHE_DIRNAME),
2877
+ rootFolderPath: path.join(process.cwd(), DEFAULT_EXECUTION_CACHE_DIRNAME),
2878
2878
  }),
2879
2879
  isCacheReloaded: isCacheReloaded,
2880
2880
  }])];
@@ -3051,7 +3051,7 @@
3051
3051
  console.info(colors__default["default"].yellow(cwd) + ' ' + colors__default["default"].green(command) + ' ' + colors__default["default"].blue(args.join(' ')));
3052
3052
  }
3053
3053
  try {
3054
- var commandProcess = node_child_process.spawn(command, args, { cwd: cwd, shell: true });
3054
+ var commandProcess = child_process.spawn(command, args, { cwd: cwd, shell: true });
3055
3055
  if (isVerbose) {
3056
3056
  commandProcess.on('message', function (message) {
3057
3057
  console.info({ message: message });
@@ -3237,7 +3237,7 @@
3237
3237
  function locateAppOnWindows(_a) {
3238
3238
  var appName = _a.appName, windowsSuffix = _a.windowsSuffix;
3239
3239
  return __awaiter(this, void 0, void 0, function () {
3240
- var prefixes, prefixes_1, prefixes_1_1, prefix, path, e_1_1, error_1;
3240
+ var prefixes, prefixes_1, prefixes_1_1, prefix, path$1, e_1_1, error_1;
3241
3241
  var e_1, _b;
3242
3242
  return __generator(this, function (_c) {
3243
3243
  switch (_c.label) {
@@ -3245,7 +3245,7 @@
3245
3245
  _c.trys.push([0, 9, , 10]);
3246
3246
  prefixes = [
3247
3247
  process.env.LOCALAPPDATA,
3248
- node_path.join(process.env.LOCALAPPDATA || '', 'Programs'),
3248
+ path.join(process.env.LOCALAPPDATA || '', 'Programs'),
3249
3249
  process.env.PROGRAMFILES,
3250
3250
  process.env['PROGRAMFILES(X86)'],
3251
3251
  ];
@@ -3257,11 +3257,11 @@
3257
3257
  case 2:
3258
3258
  if (!!prefixes_1_1.done) return [3 /*break*/, 5];
3259
3259
  prefix = prefixes_1_1.value;
3260
- path = prefix + windowsSuffix;
3261
- return [4 /*yield*/, isExecutable(path, $provideFilesystemForNode())];
3260
+ path$1 = prefix + windowsSuffix;
3261
+ return [4 /*yield*/, isExecutable(path$1, $provideFilesystemForNode())];
3262
3262
  case 3:
3263
3263
  if (_c.sent()) {
3264
- return [2 /*return*/, path];
3264
+ return [2 /*return*/, path$1];
3265
3265
  }
3266
3266
  _c.label = 4;
3267
3267
  case 4:
@@ -4935,6 +4935,24 @@
4935
4935
  var finalResultPromise = /* not await */ taskProcessCallback(function (newOngoingResult) {
4936
4936
  partialResultSubject.next(newOngoingResult);
4937
4937
  });
4938
+ finalResultPromise
4939
+ .catch(function (error) {
4940
+ // console.error('!!!!! Task failed:', error);
4941
+ partialResultSubject.error(error);
4942
+ })
4943
+ .then(function (value) {
4944
+ // console.error('!!!!! Task finished:', value);
4945
+ if (value) {
4946
+ try {
4947
+ assertsTaskSuccessful(value);
4948
+ partialResultSubject.next(value);
4949
+ }
4950
+ catch (error) {
4951
+ partialResultSubject.error(error);
4952
+ }
4953
+ }
4954
+ partialResultSubject.complete();
4955
+ });
4938
4956
  function asPromise(options) {
4939
4957
  return __awaiter(this, void 0, void 0, function () {
4940
4958
  var _a, isCrashedOnError, finalResult;
@@ -4945,7 +4963,9 @@
4945
4963
  return [4 /*yield*/, finalResultPromise];
4946
4964
  case 1:
4947
4965
  finalResult = _b.sent();
4966
+ console.error('!!!!! finalResult:', finalResult);
4948
4967
  if (isCrashedOnError) {
4968
+ console.error('!!!!! isCrashedOnError:', finalResult);
4949
4969
  assertsTaskSuccessful(finalResult);
4950
4970
  }
4951
4971
  return [2 /*return*/, finalResult];
@@ -4958,9 +4978,7 @@
4958
4978
  taskId: taskId,
4959
4979
  asPromise: asPromise,
4960
4980
  asObservable: function () {
4961
- return rxjs.concat(partialResultSubject.asObservable(), rxjs.from(asPromise({
4962
- isCrashedOnError: true,
4963
- })));
4981
+ return partialResultSubject.asObservable();
4964
4982
  },
4965
4983
  get currentValue() {
4966
4984
  return partialResultSubject.value;
@@ -7374,9 +7392,9 @@
7374
7392
  }
7375
7393
  basename = url.split('/').pop() || titleToName(url);
7376
7394
  hash = sha256__default["default"](hexEncoder__default["default"].parse(url)).toString( /* hex */);
7377
- rootDirname_1 = node_path.join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
7378
- filepath = node_path.join.apply(void 0, __spreadArray(__spreadArray([], __read(nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */)), false), ["".concat(basename.substring(0, MAX_FILENAME_LENGTH), ".").concat(mimeTypeToExtension(mimeType))], false));
7379
- return [4 /*yield*/, tools.fs.mkdir(node_path.dirname(node_path.join(rootDirname_1, filepath)), { recursive: true })];
7395
+ rootDirname_1 = path.join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
7396
+ filepath = path.join.apply(void 0, __spreadArray(__spreadArray([], __read(nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */)), false), ["".concat(basename.substring(0, MAX_FILENAME_LENGTH), ".").concat(mimeTypeToExtension(mimeType))], false));
7397
+ return [4 /*yield*/, tools.fs.mkdir(path.dirname(path.join(rootDirname_1, filepath)), { recursive: true })];
7380
7398
  case 2:
7381
7399
  _h.sent();
7382
7400
  _g = (_f = Buffer).from;
@@ -7386,7 +7404,7 @@
7386
7404
  if (fileContent.length > DEFAULT_MAX_FILE_SIZE /* <- TODO: Allow to pass different value to remote server */) {
7387
7405
  throw new LimitReachedError("File is too large (".concat(Math.round(fileContent.length / 1024 / 1024), "MB). Maximum allowed size is ").concat(Math.round(DEFAULT_MAX_FILE_SIZE / 1024 / 1024), "MB."));
7388
7406
  }
7389
- return [4 /*yield*/, tools.fs.writeFile(node_path.join(rootDirname_1, filepath), fileContent)];
7407
+ return [4 /*yield*/, tools.fs.writeFile(path.join(rootDirname_1, filepath), fileContent)];
7390
7408
  case 4:
7391
7409
  _h.sent();
7392
7410
  // TODO: [💵] Check the file security
@@ -7402,7 +7420,7 @@
7402
7420
  throw new EnvironmentMismatchError('Can not import file knowledge in non-file pipeline');
7403
7421
  // <- TODO: [🧠] What is the best error type here`
7404
7422
  }
7405
- filename_1 = node_path.join(rootDirname, knowledgeSourceContent).split('\\').join('/');
7423
+ filename_1 = path.join(rootDirname, knowledgeSourceContent).split('\\').join('/');
7406
7424
  fileExtension = getFileExtension(filename_1);
7407
7425
  mimeType = extensionToMimeType(fileExtension || '');
7408
7426
  return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
@@ -11869,19 +11887,19 @@
11869
11887
  * @returns List of all files in the directory
11870
11888
  * @private internal function of `createCollectionFromDirectory`
11871
11889
  */
11872
- function listAllFiles(path, isRecursive, fs) {
11890
+ function listAllFiles(path$1, isRecursive, fs) {
11873
11891
  return __awaiter(this, void 0, void 0, function () {
11874
11892
  var dirents, fileNames, _a, _b, dirent, subPath, _c, _d, _e, _f, e_1_1;
11875
11893
  var e_1, _g;
11876
11894
  return __generator(this, function (_h) {
11877
11895
  switch (_h.label) {
11878
- case 0: return [4 /*yield*/, isDirectoryExisting(path, fs)];
11896
+ case 0: return [4 /*yield*/, isDirectoryExisting(path$1, fs)];
11879
11897
  case 1:
11880
11898
  if (!(_h.sent())) {
11881
- throw new Error("Directory \"".concat(path, "\" does not exist or is not readable"));
11899
+ throw new Error("Directory \"".concat(path$1, "\" does not exist or is not readable"));
11882
11900
  // <- TODO: Use some custom error class
11883
11901
  }
11884
- return [4 /*yield*/, fs.readdir(path, {
11902
+ return [4 /*yield*/, fs.readdir(path$1, {
11885
11903
  withFileTypes: true /* Note: This is not working: recursive: isRecursive */,
11886
11904
  })];
11887
11905
  case 2:
@@ -11890,7 +11908,7 @@
11890
11908
  .filter(function (dirent) { return dirent.isFile(); })
11891
11909
  .map(function (_a) {
11892
11910
  var name = _a.name;
11893
- return node_path.join(path, name).split('\\').join('/');
11911
+ return path.join(path$1, name).split('\\').join('/');
11894
11912
  });
11895
11913
  if (!isRecursive) return [3 /*break*/, 10];
11896
11914
  _h.label = 3;
@@ -11901,7 +11919,7 @@
11901
11919
  case 4:
11902
11920
  if (!!_b.done) return [3 /*break*/, 7];
11903
11921
  dirent = _b.value;
11904
- subPath = node_path.join(path, dirent.name);
11922
+ subPath = path.join(path$1, dirent.name);
11905
11923
  _d = (_c = fileNames.push).apply;
11906
11924
  _e = [fileNames];
11907
11925
  _f = [[]];
@@ -12032,7 +12050,7 @@
12032
12050
  * @returns PipelineCollection
12033
12051
  * @public exported from `@promptbook/node`
12034
12052
  */
12035
- function createCollectionFromDirectory(path, tools, options) {
12053
+ function createCollectionFromDirectory(path$1, tools, options) {
12036
12054
  return __awaiter(this, void 0, void 0, function () {
12037
12055
  var madeLibraryFilePath, _a, _b, isRecursive, _c, isVerbose, _d, isLazyLoaded, _e, isCrashedOnError, rootUrl, collection;
12038
12056
  var _this = this;
@@ -12049,7 +12067,7 @@
12049
12067
  throw new EnvironmentMismatchError('Can not create collection without filesystem tools');
12050
12068
  // <- TODO: [🧠] What is the best error type here`
12051
12069
  }
12052
- madeLibraryFilePath = node_path.join(path, "".concat(DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME
12070
+ madeLibraryFilePath = path.join(path$1, "".concat(DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME
12053
12071
  // <- TODO: [🦒] Allow to override (pass different value into the function)
12054
12072
  , ".json"));
12055
12073
  return [4 /*yield*/, isFileExisting(madeLibraryFilePath, tools.fs)];
@@ -12068,9 +12086,9 @@
12068
12086
  switch (_b.label) {
12069
12087
  case 0:
12070
12088
  if (isVerbose) {
12071
- console.info(colors__default["default"].cyan("Creating pipeline collection from path ".concat(path.split('\\').join('/'))));
12089
+ console.info(colors__default["default"].cyan("Creating pipeline collection from path ".concat(path$1.split('\\').join('/'))));
12072
12090
  }
12073
- return [4 /*yield*/, listAllFiles(path, isRecursive, tools.fs)];
12091
+ return [4 /*yield*/, listAllFiles(path$1, isRecursive, tools.fs)];
12074
12092
  case 1:
12075
12093
  fileNames = _b.sent();
12076
12094
  // Note: First load all .book.json and then .book.md files
@@ -12091,7 +12109,7 @@
12091
12109
  switch (_f.label) {
12092
12110
  case 0:
12093
12111
  sourceFile = './' + fileName.split('\\').join('/');
12094
- rootDirname = node_path.dirname(sourceFile).split('\\').join('/');
12112
+ rootDirname = path.dirname(sourceFile).split('\\').join('/');
12095
12113
  _f.label = 1;
12096
12114
  case 1:
12097
12115
  _f.trys.push([1, 8, , 9]);
@@ -12326,7 +12344,7 @@
12326
12344
  makeCommand.option('-v, --verbose', "Is output verbose", false);
12327
12345
  makeCommand.option('-o, --output <path>', spaceTrim__default["default"]("\n Where to save the builded collection\n\n Note: If you keep it \"".concat(DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME, "\" it will be saved in the root of the promptbook directory\n If you set it to a path, it will be saved in that path\n BUT you can use only one format and set correct extension\n ")), DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME);
12328
12346
  makeCommand.option('-fn, --function-name <functionName>', spaceTrim__default["default"]("\n Name of the function to get pipeline collection\n\n Note: This can be used only with \"javascript\" or \"typescript\" format\n\n "), DEFAULT_GET_PIPELINE_COLLECTION_FUNCTION_NAME);
12329
- makeCommand.action(function (path, _a) {
12347
+ makeCommand.action(function (path$1, _a) {
12330
12348
  var projectName = _a.projectName, rootUrl = _a.rootUrl, format = _a.format, functionName = _a.functionName, validation = _a.validation, isCacheReloaded = _a.reload, isVerbose = _a.verbose, output = _a.output;
12331
12349
  return __awaiter(_this, void 0, void 0, function () {
12332
12350
  var formats, validations, prepareAndScrapeOptions, fs, llm, executables, tools, collection, pipelinesUrls, validations_1, validations_1_1, validation_1, pipelinesUrls_1, pipelinesUrls_1_1, pipelineUrl, pipeline, e_1_1, e_2_1, collectionJson, collectionJsonString, collectionJsonItems, saveFile;
@@ -12378,7 +12396,7 @@
12378
12396
  /*new JavascriptExecutionTools(options)*/
12379
12397
  ],
12380
12398
  _b);
12381
- return [4 /*yield*/, createCollectionFromDirectory(path, tools, {
12399
+ return [4 /*yield*/, createCollectionFromDirectory(path$1, tools, {
12382
12400
  isVerbose: isVerbose,
12383
12401
  rootUrl: rootUrl,
12384
12402
  isRecursive: true,
@@ -12392,7 +12410,7 @@
12392
12410
  case 5:
12393
12411
  pipelinesUrls = _e.sent();
12394
12412
  if (pipelinesUrls.length === 0) {
12395
- console.error(colors__default["default"].red("No books found in \"".concat(path, "\"")));
12413
+ console.error(colors__default["default"].red("No books found in \"".concat(path$1, "\"")));
12396
12414
  return [2 /*return*/, process.exit(1)];
12397
12415
  }
12398
12416
  _e.label = 6;
@@ -12471,11 +12489,11 @@
12471
12489
  case 0:
12472
12490
  filename = output !== DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME
12473
12491
  ? output
12474
- : node_path.join(path, "".concat(DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME, ".").concat(extension));
12492
+ : path.join(path$1, "".concat(DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME, ".").concat(extension));
12475
12493
  if (!output.endsWith(".".concat(extension))) {
12476
12494
  console.warn(colors__default["default"].yellow("Warning: Extension of output file should be \"".concat(extension, "\"")));
12477
12495
  }
12478
- return [4 /*yield*/, promises.mkdir(node_path.dirname(filename), { recursive: true })];
12496
+ return [4 /*yield*/, promises.mkdir(path.dirname(filename), { recursive: true })];
12479
12497
  case 1:
12480
12498
  _a.sent();
12481
12499
  return [4 /*yield*/, promises.writeFile(filename, content, 'utf-8')];
@@ -13090,7 +13108,7 @@
13090
13108
  return __generator(this, function (_d) {
13091
13109
  switch (_d.label) {
13092
13110
  case 0:
13093
- booksDirname = node_path.join(rootDirname, DEFAULT_BOOKS_DIRNAME /* <- TODO: [🕝] Make here more candidates */);
13111
+ booksDirname = path.join(rootDirname, DEFAULT_BOOKS_DIRNAME /* <- TODO: [🕝] Make here more candidates */);
13094
13112
  return [4 /*yield*/, isDirectoryExisting(booksDirname, fs)];
13095
13113
  case 1:
13096
13114
  if (!_d.sent()) return [3 /*break*/, 4];
@@ -13128,7 +13146,7 @@
13128
13146
  return [2 /*return*/, "break-up_to_root"];
13129
13147
  }
13130
13148
  // Note: If the directory does not exist, try the parent directory
13131
- rootDirname = node_path.join(rootDirname, '..');
13149
+ rootDirname = path.join(rootDirname, '..');
13132
13150
  return [2 /*return*/];
13133
13151
  }
13134
13152
  });
@@ -13367,7 +13385,7 @@
13367
13385
  return [4 /*yield*/, isFileExisting('.env', fs)];
13368
13386
  case 4:
13369
13387
  if (!!(_m.sent())) return [3 /*break*/, 6];
13370
- return [4 /*yield*/, promises.writeFile(node_path.join(process.cwd(), '.env'), $llmToolsMetadataRegister
13388
+ return [4 /*yield*/, promises.writeFile(path.join(process.cwd(), '.env'), $llmToolsMetadataRegister
13371
13389
  .list()
13372
13390
  .flatMap(function (_a) {
13373
13391
  var title = _a.title, envVariables = _a.envVariables;
@@ -13795,7 +13813,7 @@
13795
13813
  next();
13796
13814
  });
13797
13815
  var runningExecutionTasks = [];
13798
- // TODO: !!!!!! Do here some garbage collection of finished tasks
13816
+ // TODO: [🧠] Do here some garbage collection of finished tasks
13799
13817
  app.get(['/', rootPath], function (request, response) { return __awaiter(_this, void 0, void 0, function () {
13800
13818
  var _a, _b;
13801
13819
  var _this = this;
@@ -13844,20 +13862,19 @@
13844
13862
  });
13845
13863
  }); });
13846
13864
  app.get("".concat(rootPath, "/books"), function (request, response) { return __awaiter(_this, void 0, void 0, function () {
13847
- var _a, _b, _c;
13848
- return __generator(this, function (_d) {
13849
- switch (_d.label) {
13865
+ var pipelines;
13866
+ return __generator(this, function (_a) {
13867
+ switch (_a.label) {
13850
13868
  case 0:
13851
- _b = (_a = response).send;
13852
- if (!(collection === null)) return [3 /*break*/, 1];
13853
- _c = [];
13854
- return [3 /*break*/, 3];
13855
- case 1: return [4 /*yield*/, collection.listPipelines()];
13856
- case 2:
13857
- _c = _d.sent();
13858
- _d.label = 3;
13859
- case 3:
13860
- _b.apply(_a, [_c]);
13869
+ if (collection === null) {
13870
+ response.status(500).send('No collection available');
13871
+ return [2 /*return*/];
13872
+ }
13873
+ return [4 /*yield*/, collection.listPipelines()];
13874
+ case 1:
13875
+ pipelines = _a.sent();
13876
+ // <- TODO: [🧠][👩🏾‍🤝‍🧑🏿] List `inputParameters` required for the execution
13877
+ response.send(pipelines);
13861
13878
  return [2 /*return*/];
13862
13879
  }
13863
13880
  });
@@ -13887,13 +13904,12 @@
13887
13904
  return __generator(this, function (_b) {
13888
13905
  switch (_b.label) {
13889
13906
  case 0:
13890
- _b.trys.push([0, 5, , 6]);
13907
+ _b.trys.push([0, 6, , 7]);
13891
13908
  inputParameters = request.body.inputParameters;
13892
13909
  pipelineUrl = request.body.pipelineUrl || request.body.book;
13893
13910
  return [4 /*yield*/, (collection === null || collection === void 0 ? void 0 : collection.getPipelineByUrl(pipelineUrl))];
13894
13911
  case 1:
13895
13912
  pipeline = _b.sent();
13896
- // <- TODO: !!!!!! NotFoundError
13897
13913
  if (pipeline === undefined) {
13898
13914
  response.status(404).send("Pipeline \"".concat(pipelineUrl, "\" not found"));
13899
13915
  return [2 /*return*/];
@@ -13920,20 +13936,21 @@
13920
13936
  pipelineExecutor = createPipelineExecutor(__assign({ pipeline: pipeline, tools: tools }, options));
13921
13937
  executionTask = pipelineExecutor(inputParameters);
13922
13938
  runningExecutionTasks.push(executionTask);
13923
- response.send(executionTask);
13924
- // TODO: !!!!!! Remove this:
13925
- executionTask.asObservable().subscribe(function (_) {
13926
- console.log('!!!', _);
13927
- });
13928
- return [3 /*break*/, 6];
13939
+ return [4 /*yield*/, waitasecond.forTime(10)];
13929
13940
  case 5:
13941
+ _b.sent();
13942
+ // <- Note: Wait for a while to wait for quick responses or sudden but asynchronous errors
13943
+ // <- TODO: Put this into configuration
13944
+ response.send(executionTask);
13945
+ return [3 /*break*/, 7];
13946
+ case 6:
13930
13947
  error_1 = _b.sent();
13931
13948
  if (!(error_1 instanceof Error)) {
13932
13949
  throw error_1;
13933
13950
  }
13934
13951
  response.status(400).send({ error: serializeError(error_1) });
13935
- return [3 /*break*/, 6];
13936
- case 6: return [2 /*return*/];
13952
+ return [3 /*break*/, 7];
13953
+ case 7: return [2 /*return*/];
13937
13954
  }
13938
13955
  });
13939
13956
  }); });
@@ -14212,21 +14229,30 @@
14212
14229
  // <- TODO: [🧟‍♂️] Unite path to promptbook collection argument
14213
14230
  'Path to promptbook collection directory', DEFAULT_BOOKS_DIRNAME);
14214
14231
  startServerCommand.option('--port <port>', "Port to start the server on", '4460');
14215
- startServerCommand.option('-u, --url', spaceTrim__default["default"]("\n Public root url of the server\n It is used for following purposes:\n\n 1) It is suffixed with /books and used as rootUrl for all served books\n 2) Path (if not just /) is used as rootPath for the server\n "));
14232
+ startServerCommand.option('-u, --url <url>', spaceTrim__default["default"]("\n Public root url of the server\n It is used for following purposes:\n\n 1) It is suffixed with /books and used as rootUrl for all served books\n 2) Path (if not just /) is used as rootPath for the server\n "));
14216
14233
  startServerCommand.option('--allow-anonymous', "Is anonymous mode allowed", false);
14217
14234
  startServerCommand.option('-r, --reload', "Call LLM models even if same prompt with result is in the cache", false);
14218
14235
  startServerCommand.option('-v, --verbose', "Is output verbose", false);
14219
14236
  startServerCommand.description(spaceTrim__default["default"]("\n Starts a remote server to execute books\n "));
14220
14237
  startServerCommand.action(function (path, _a) {
14221
- var port = _a.port, rawUrl = _a.url, isAnonymousModeAllowed = _a.allowAnonymous, isCacheReloaded = _a.reload, isVerbose = _a.verbose;
14238
+ var portRaw = _a.port, rawUrl = _a.url, isAnonymousModeAllowed = _a.allowAnonymous, isCacheReloaded = _a.reload, isVerbose = _a.verbose;
14222
14239
  return __awaiter(_this, void 0, void 0, function () {
14223
- var url, rootUrl, rootPath, prepareAndScrapeOptions, fs, llm, executables, tools, collection;
14240
+ var port, url, rootUrl, rootPath, prepareAndScrapeOptions, fs, llm, executables, tools, collection;
14224
14241
  var _b;
14225
14242
  return __generator(this, function (_c) {
14226
14243
  switch (_c.label) {
14227
14244
  case 0:
14245
+ if (rawUrl && !isValidUrl(rawUrl)) {
14246
+ console.error(colors__default["default"].red("Invalid URL: ".concat(rawUrl)));
14247
+ return [2 /*return*/, process.exit(1)];
14248
+ }
14249
+ port = parseInt(portRaw, 10);
14250
+ if (isNaN(port) || port <= 0 || port > 65535) {
14251
+ console.error(colors__default["default"].red("Invalid port number: ".concat(portRaw)));
14252
+ return [2 /*return*/, process.exit(1)];
14253
+ }
14228
14254
  url = !rawUrl ? null : new URL(rawUrl);
14229
- if (url !== null && url.port !== port) {
14255
+ if (url !== null && url.port !== port.toString()) {
14230
14256
  console.warn(colors__default["default"].yellow("Port in --url is different from --port which the server will listen on, this is ok only if you proxy from one port to another, for exaple via nginx or docker"));
14231
14257
  }
14232
14258
  rootUrl = undefined;
@@ -14271,7 +14297,7 @@
14271
14297
  collection = _c.sent();
14272
14298
  startRemoteServer({
14273
14299
  rootPath: rootPath,
14274
- port: parseInt(port, 10),
14300
+ port: port,
14275
14301
  isAnonymousModeAllowed: isAnonymousModeAllowed,
14276
14302
  isApplicationModeAllowed: true,
14277
14303
  collection: collection,
@@ -14280,7 +14306,11 @@
14280
14306
  return llm;
14281
14307
  },
14282
14308
  });
14283
- return [2 /*return*/];
14309
+ return [4 /*yield*/, waitasecond.forEver()];
14310
+ case 5:
14311
+ // Note: Already logged by `startRemoteServer`
14312
+ // console.error(colors.green(`Server started on port ${port}`));
14313
+ return [2 /*return*/, _c.sent()];
14284
14314
  }
14285
14315
  });
14286
14316
  });
@@ -17059,12 +17089,12 @@
17059
17089
  semanticName = normalizeToKebabCase(titleToName((sourceFilename || url || '').split('intermediate').join(''))).substring(0, 20);
17060
17090
  pieces = ['intermediate', semanticName, hash].filter(function (piece) { return piece !== ''; });
17061
17091
  name = pieces.join('-').split('--').join('-');
17062
- cacheFilename = node_path.join.apply(void 0, __spreadArray(__spreadArray([process.cwd(),
17092
+ cacheFilename = path.join.apply(void 0, __spreadArray(__spreadArray([process.cwd(),
17063
17093
  cacheDirname], __read(nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */)), false), [name], false)).split('\\')
17064
17094
  .join('/') +
17065
17095
  '.' +
17066
17096
  extension;
17067
- return [4 /*yield*/, promises.mkdir(node_path.dirname(cacheFilename), { recursive: true })];
17097
+ return [4 /*yield*/, promises.mkdir(path.dirname(cacheFilename), { recursive: true })];
17068
17098
  case 1:
17069
17099
  _a.sent();
17070
17100
  isDestroyed = true;
@@ -17769,7 +17799,7 @@
17769
17799
  return [4 /*yield*/, isFileExisting(cacheFilehandler.filename, this.tools.fs)];
17770
17800
  case 2:
17771
17801
  if (!!(_g.sent())) return [3 /*break*/, 8];
17772
- documentSourceOutdirPathForLibreOffice_1 = node_path.join(node_path.dirname(cacheFilehandler.filename), 'libreoffice')
17802
+ documentSourceOutdirPathForLibreOffice_1 = path.join(path.dirname(cacheFilehandler.filename), 'libreoffice')
17773
17803
  .split('\\')
17774
17804
  .join('/');
17775
17805
  command_1 = "\"".concat(this.tools.executables.libreOfficePath, "\" --headless --convert-to docx \"").concat(source.filename, "\" --outdir \"").concat(documentSourceOutdirPathForLibreOffice_1, "\"");
@@ -17783,7 +17813,7 @@
17783
17813
  throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n Expected exactly 1 file in the LibreOffice output directory, got ".concat(files_1.length, "\n\n The temporary folder:\n ").concat(block(documentSourceOutdirPathForLibreOffice_1), "\n\n Command:\n > ").concat(block(command_1), "\n "); }));
17784
17814
  }
17785
17815
  file = files_1[0];
17786
- return [4 /*yield*/, promises.rename(node_path.join(documentSourceOutdirPathForLibreOffice_1, file), cacheFilehandler.filename)];
17816
+ return [4 /*yield*/, promises.rename(path.join(documentSourceOutdirPathForLibreOffice_1, file), cacheFilehandler.filename)];
17787
17817
  case 5:
17788
17818
  _g.sent();
17789
17819
  return [4 /*yield*/, promises.rmdir(documentSourceOutdirPathForLibreOffice_1)];